Jump to content

Connecting to ODBC by ip address...


tfburges

Recommended Posts

Suppose there's a server with the IP address 10.20.30.40 containing ODBC with data I'd like to retrieve, and suppose the database is located within the directory "first_dir\second_dir\example\source.rbm."

 

What's the command to connect and reach that source?  I've read through php's manual and googled a few different things but I haven't quite found what I need.

 

This is where I am:

$conn = odbc_connect('10.20.30.40', $user, $pass);
if ($conn <= 0) {
  echo "Could not connect.";
  exit;
} else {
  echo  "Connection successful.";
}

 

I've tried listing the directory after the IP and a few other variations.

What's the syntax?

 

I'll keep searching...

Link to comment
Share on other sites

Another question... why would I want to use a MySQL driver when there are perfectly applicable commands for odbc?

 

Like this:

$dsn =         "DRIVER={MySQL ODBC 3.51 Driver};" . 
            "CommLinks=tcpip(Host=$db_host);" . 
            "DatabaseName=$db_name;" . 
            "uid=$db_user; pwd=$db_pass";

 

Why not just stick with ODBC?  And when using odbc_connect or odbc_pconnect, do I have to use the same syntax as the code above?

Link to comment
Share on other sites

I just tried this and no worky...

 

$odbchost = '10.20.30.40';
$odbcuser = 'user';
$odbcpass = 'pass';
$odbcdbname = 'directories\example.rbm';
$dsn = "DRIVER={CSI RBM 4.02 ODBC Driver};" . 
        "CommLinks=tcpip(Host=$odbchost;" . 
        "DatabaseName=$odbcdbname;" . 
        "uid=$odbcuser; pwd=$odbcpass";
$conn = odbc_connect($dsn, $odbcuser, $odbcpass);
if ($conn <= 0) {
  echo "Connection failed.";
  exit;
} else {
  echo  "Connection successful.";
}

 

I've also tried changing "CSI RBM 4.02 ODBC Driver" to the actual location of the driver dll.

Link to comment
Share on other sites

I'm positive.  I can query the database through Microsoft Access.

 

I'm getting the following error:

Warning: odbc_pconnect() [function.odbc-pconnect]: SQL error: [sYWARE, Inc.][Dr. DeeBee ODBC Driver]Unable to connect, SQL state 08001 in SQLConnect in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\admin\notifications.php on line 20
DRIVER={CSI RBM 4.02 ODBC Driver};CommLinks=tcpip(Host=rbm1;DatabaseName=\\rbm1\rbmnet\RBMsuite\CustData\RbmS\Example.rbm;uid=user; pwd=pass
Connection failed.

 

And the code up to that point:

 $odbc_host = 'rbm1';
$odbc_user = 'user';
$odbc_pass = 'pass';
$odbc_dbname = '\\\\rbm1\\rbmnet\\RBMsuite\\CustData\\RbmS\\Example.rbm';
$odbc_dsn = "DRIVER={CSI RBM 4.02 ODBC Driver};" . 
       "CommLinks=tcpip(Host=$odbc_host;" . 
       "DatabaseName=$odbc_dbname;" . 
       "uid=$odbc_user; pwd=$odbc_pass";
$odbc_connect = odbc_pconnect($odbc_dsn, $odbc_user, $odbc_pass);
echo $odbc_dsn,"<br>";
if ($odbc_connect <= 0) {
 echo "Connection failed.";
 exit;
} else {
 echo  "Connection successful.";
}

 

(Sensitive information has of course been replaced.)

Link to comment
Share on other sites

it doesn't matter where the data is on the remote server. you should only request the actual name of the database, not the path to the database file.

 

$odbcdbname = 'example';

Thanks for the reply.

 

I've tried this but to no avail.  I just tried again just to make sure and I'm receiving the same message.

 

 $odbc_host = 'rbm1';
$odbc_user = 'user';
$odbc_pass = 'pass';
$odbc_dbname = 'Example.rbm';
$odbc_dsn = "DRIVER={CSI RBM 4.02 ODBC Driver};" . 
        "CommLinks=tcpip(Host=$odbc_host;" . 
        "DatabaseName=$odbc_dbname;" . 
        "uid=$odbc_user; pwd=$odbc_pass";
$odbc_connect = odbc_pconnect($odbc_dsn, $odbc_user, $odbc_pass);
echo $odbc_dsn,"<br>";
if ($odbc_connect <= 0) {
  echo "Connection failed.";
  exit;
} else {
  echo  "Connection successful.";
}

Link to comment
Share on other sites

at first glance, it appears you don't have permission to connect to the server.

 

i don't know why you'd use ODBC when you could just use mysql_ functions. you'd be able to remove a lot of possible problems using only one statement instead of all that ODBC stuff.

 

mysql_connect('10.20.30.40', $user, $pass); // no need for any DSN ODBC stuff.

 

Link to comment
Share on other sites

it looks like you're using a MySQL ODBC driver here:

 

DRIVER={MySQL ODBC 3.51 Driver};

 

no?

 

What kind of database are you connecting to? ODBC is not a database, it is a method of connecting to a database. if you're connecting to a MySQL server, i'd use mysql_ commands. if you're NOT connecting to MySQL, you're probably using the wrong ODBC driver. my advice: try to avoid ODBC if at all possible. been there, done that, and it's way more work than it needs to be.

Link to comment
Share on other sites

That MySQL Driver stuff was some code I pulled off another web site that I was inquiring about.  Turns out it's not what I'm looking for anyway.

 

I'm positive that the driver I'm using now is the right one because I'm using the same one to query the database in Access.

 

And I wish I could change the server but I can't without tons of work.  The server isn't my doing anyway.  All I really need to be able to do is retrieve some data from it through PHP.

 

I hate it when stuff like this happens.  It shouldn't be so complicated!

Link to comment
Share on other sites

Is it possible that the driver simply can't handle queries from php?  I've searched all over the place for information on this driver and it is apparently not used anywhere other than where I work LOL.  I don't think I've found information on it in more than 3 places and they were of no help whatsoever.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.