Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>PDO</h2> <p>If you want to interface with an MS Access database using PHP, <a href="http://php.net/manual/en/book.pdo.php" rel="nofollow noreferrer">PDO</a> is available for you. </p> <pre><code>&lt;?php try { $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin"); } catch (PDOException $e) { echo $e-&gt;getMessage(); } </code></pre> <p>When using PDO, due to the unified interface for DB operations, you have the opportunity to make your app more portable across various RDBMs systems. All you have to do is to provide the connection string to the PDO new instance and <strong>have the correct PDO driver installed</strong>. </p> <p>As the result of this unified interface, your application can be easily ported from MS Access to MySQL, SQLite, Oracle, Informix, DB2, etc. which most certainly is the case if it ages enough. </p> <p>Here's an insertion example: </p> <pre><code>&lt;?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-&gt;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-&gt;getMessage(); } </code></pre> <h3>ODBC</h3> <p>In case you don't want to use PDO for some insane reasons, you can look into <a href="https://secure.php.net/manual/en/book.uodbc.php" rel="nofollow noreferrer">ODBC</a>. </p> <p>Here's an example: </p> <pre><code>&lt;?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); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload