Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top