D_Wagner
D_Wagner

Reputation: 87

PHP Cannot connect to PDO ODBC Driver

My php cannot find my odbc driver. I've downloaded and re-installed multiple times. Can anyone help me with this error:

QLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified"

Here is my php code:

$dbName = "C:\Users\David\Documents\SCHOOLNEW\Assignment5-PROG1800\database\as4.mdb";
if (!file_exists($dbName))
{
    die("Could not find database file.");
}
try 
{
    // Connect
    $dbh = new PDO("odbc:Driver={Microsoft Access Driver(*.mdb, *.accdb)};Dbq=C:\Users\David\Documents\SCHOOLNEW\Assignment5-PROG1800\database\as4.mdb;Uid=Admin");

    // INSERT data
    $count = $dbh->exec("INSERT INTO part(vendorNo,description,onHand,onOrder,cost,listPrice) VALUES ('$vendorNo', '$desc', '$onHand', '$onOrder', '$cost', '$listPrice')");

    // echo the number of affected rows
    echo $count;

    // close the database connection
    $dbh = null;

}

catch(PDOException $e)
{
    echo $e->getMessage();
} 

I'm running php with apache on xampp. This all on a local machine. My system is 64 bits. I'm not sure if it has something to do with the system and drive types or my syntax or certain drivers I need to install. I just want to insert data from my form into the database on my computer.

Upvotes: 1

Views: 1920

Answers (2)

Gord Thompson
Gord Thompson

Reputation: 123839

Driver={Microsoft Access Driver(*.mdb, *.accdb)}

is not a valid ODBC driver name because it is missing a space. The correct name for the newer "ACE" ODBC driver is

Driver={Microsoft Access Driver (*.mdb, *.accdb)}

However, in this case PHP is running in the 32-bit environment and trying to open an .mdb database so the older "Jet" ODBC driver ...

Driver={Microsoft Access Driver (*.mdb)}

... will work, too.

Upvotes: 2

david419
david419

Reputation: 435

Can you place the path after escaping the slashes and then try:-

$dbName = "C:\\Users\\David\\Documents\\SCHOOLNEW\\Assignment5-PROG1800\\database\\as4.mdb";

Escape the slashes in all the paths you have provided in the code and then try.

Upvotes: 0

Related Questions