1

i have site hosted on bluehost.com (Linux Server), i have use case that i have to Export some Specific Data Export to MS Access File,

I have following code to Connect with MS Access File:

$dbh = null;    
try{
  $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_path", $user_name, $password, $db_info);
}catch(PDOException $e){
  echo $e->getMessage();      
}   
return $dbh;

But when i run the above code on Hosting server than i got error SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified

Later after some searching i changed the code of DB connection to

try{
  $conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_path", ACCESS_DB_USERNAME, ACCESS_DB_PASSWORD);
}catch(Exception $ex){
  echo $ex->getMessage();
}

in above code i did not get any exception but $conn is NULL, both code snippet working fine on my local Windows machine,

Can you people help me in fixing issue?? i want to make connection and want to run INSERT INTO statement on MS Access DB.

3
  • As the error message suggests you are missing Drivers for that type of database Commented Mar 14, 2013 at 12:05
  • Your host does not have an ODBC driver installed called "Microsoft Access Driver (*.mdb)". If they actually provide such service, they should have documentation somewhere with the correct driver names. Commented Mar 14, 2013 at 12:06
  • but when i use odbc_connect i did not get any error, assuming i am doing something wrong, Commented Mar 14, 2013 at 12:21

1 Answer 1

2

The docs for odbc_connect say it returns one of two things.

  1. An ODBC connection.
  2. FALSE on error.

Your code should look for FALSE, not for an exception.

The docs also have examples of several different kinds of connections. But I think the chances that Bluehost installs Microsoft Access drivers on all their Linux servers are less than zero.

Sign up to request clarification or add additional context in comments.

3 Comments

yes i think, i tried from jdbc, but not success, will try change our plan and get root access to install Linux based ODBC driver.... Thanks for your reply.
Hi Mike, i just made a call to Blue Host support they said i need Dedicated IP for Using ODBC driver, they have installed it on all their servers on Port 1433, does it make any sense to you? will appreciate your quick response. as i have no idea where we specify the PORT while making the connection.
Yeah, that kind of makes sense. The ODBC driver needs to know how to find the target database. On Bluehost, the database server is probably a different machine than the web server. And they probably want the flexibility to be able to bring up a new (probably virtual) database server, change the IP address, and have everything just work. I'm pretty sure there's technology that can make that happen without human intervention. That doesn't mean there's an open source version of it, though. If you have trouble, look at connectionstrings.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.