3

For some reasons i need to use ms-access in my PHP application therefore I have enable php_pdo_odbc extension in WAMP. Which shows in phpinfo()

But i am unable to connect the database, it returns the following error.

( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' in C:\wamp64\www...\portals...\config.php on line 15

( ! )> PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified in C:\wamp64\www...\portals...\config.php on line 15

$db_username = ''; //username
$db_password = ''; //password

//path to database file
$database_path = "StudentLogInData.mdb";

//check file exist before we proceed
if (!file_exists($database_path)) {
    die("Access database file not found !");
}

//create a new PDO object
$database = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=realpath($database_path); Uid=$db_username; Pwd=$db_password;");

I'm using WAMP 64bit version on Windows 7 (64-Bit). Searched alot of Stackoverflow's solutions for example tried running 32 bit version but it can't be installed on 64 bit. Please help how to make it work?

1 Answer 1

3

realpath() is a PHP function, not something that the ODBC driver understands. You possibly want to remove it from the DSN:

$database_path = realpath("StudentLogInData.mdb");
$database = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$database_path; Uid=$db_username; Pwd=$db_password;");

As about the driver name, you need to type ODBC in your Start menu and verify the given name is available in your Drivers tab:

ODBC Manager

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

8 Comments

Done. but same error and also tried full path in the DSN string but same error as well. I'm feeling this has to be something with 64-bit version.
Well, sorry, I had assumed you had already installed the driver that provides "Microsoft Access Driver (*.mdb, *.accdb)": microsoft.com/en-US/download/details.aspx?id=13255
I have installed it and rebooted the machine but still same error. And i checked the drivers tab i dont have MS Access listed. screenshot imgur.com/a/l4hCL
Then it clearly didn't install successfully. PHP won't be able to use the driver until it's available.
But i installed the drivers from your link. What could be done now?
|

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.