How to connect PHP Access mdb script?

Asked By 0 points N/A Posted on -

Hi guys and good day Expert community of TechyV!

I have a PHP script that I want to connect to Microsoft Access Database.

I tried it but I am struggling doing it and having a hard time to connect it.

I ask many friends about it, but sadly I none of them can solve my problem.

So Experts and computer geeks, how can solve this PHP access mdb script problem?

Are there ways or steps to do this such thing? Any help would be nice.

Thank you very much.

William Mmorriss

Answered By 0 points N/A #170314

How to connect PHP Access mdb script?


Hi William,

There are 3 ways to connect to  Microsoft access database using PHP .

1) Using ODBC (Open database connectivity) Driver.

2)Using ADDOB Object.

3) Using PHP inbuilt functions like mysql_connect ().

Using ODBC (Open database connectivity) Driver:


// Microsoft Access

$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);


 odbc_connect ( string $dsn , string $user , string $password [, int $cursor_type ] )


The database source name for the connection. Alternatively, a DSN-less connection string can be used.


The username.


The password.


This sets the type of cursor to be used for this connection. This parameter is not normally needed, but can be useful for working around problems with some ODBC drivers.

The following constants are defined for cursortype:




Using ADDOB Object.

ADODB is a database abstraction library for PHP. It allows developers to write applications in a fairly consistent way regardless of the underlying database system storing the information. The advantage is that the database system can be changed without re-writing every call to it in the application.


$db_connection = new COM("ADODB.Connection", NULL, 1251);

$db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:DataDirEmployee.mdb;DefaultDir=C:DataDir";


$rs = $db_connection->execute("SELECT EmpNameLocal, EmpPosLocal FROM tbl_Employee WHERE ID='$IDNo'");

$rs_fld0 = $rs->Fields(0);

$rs_fld1 = $rs->Fields(1);

while (!$rs->EOF) {

    $empNameLoc    = $rs_fld0->value;

    $empWPPos    = $rs_fld1->value;






Using PHP inbuilt functions like mysql_connect ().

PHP has lot of inbuilt function to work with databases.To connect to any database there is following three steps.

  • Open a connection to MySQL itself using mysql_connect() function.
  • Specify the database we want to open using mysql_select_db() function.
  • Close the connection using mysql_close() function.


$user_name = "root";
$password = "";
$database = "school";
$server = "";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

print "Database Found ";

else {

print "Database NOT Found ";



Login/Register to Answer

Related Questions