PDO
If you want to interact with the MS Access database using PHP, PDO is available for you.
<?php try { $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin"); } catch (PDOException $e) { echo $e->getMessage(); }
When using PDO, due to the unified interface for database operations, you have the opportunity to make your application more portable in various RDBM systems. All you have to do is provide a connection string for the new PDO instance and install the correct PDO driver .
As a result of this unified interface, your application is easily ported from MS Access to MySQL, SQLite, Oracle, Informix, DB2, etc., which, of course, takes place if it is large enough.
Here's an example insertion:
<?php try { // Connect, // Assuming that the DB file is available in `C:\animals.mdb` $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\animals.mdb;Uid=Admin"); // INSERT data $count = $pdo->exec("INSERT INTO animals(animal_type, animal_name) VALUES ('kiwi', 'troy')"); // echo the number of affected rows echo $count; // close the database connection // See: http://php.net/manual/en/pdo.connections.php $pdo = null; } catch (PDOException $e) { echo $e->getMessage(); }
ODBC
If you do not want to use PDO for some crazy reasons, you can watch ODBC .
Here is an example:
<?php if (! $conn = odbc_connect('northwind', '', '')) { exit("Connection Failed: $conn"); } if (! $rs = odbc_exec($conn, 'SELECT * FROM customers')) { exit('Error in SQL'); } while (odbc_fetch_row($rs)) { echo 'Company name: ', odbc_result($rs, 'CompanyName'), PHP_EOL; echo 'Contact name: ', odbc_result($rs, 'ContactName'), PHP_EOL; } odbc_close($conn);