The scripting of a MS Access database in PHP is similar to that in ASP. The syntax
is different and a different method of connection to the database has to be used.
Fortunately, PHP, an object-oriented language, provides an Open Method within
PHP's COM class. This class implements a "DSN-less" connection and also provides
an execute('SQL string') method which returns a handle to the Open-ed
Recordset eg:-
$rs = $conn->execute($query);
(The coding statements are similar in structure, if not in syntax to the ASP
Server.CreateObject(), oConn.Open() & oConn.Execute() statements.)
This allows the recordset's fields, their names and values to be reached as well as row
indexes and counts in a similar fashion to the language of the Microsoft Access
desktop application.
The panel below shows the coding for the same MS Access Authors database as in
the previous page.
|
Contacts within the Authors Database: < ?php // Map authors database to physical path $dbpath = "Authors.mdb" ; $tblname = "authors"; // Create ADO Connection Component to connect // with sample database if (!$conn = new COM ("ADODB.Connection")){ die("Unable to create an ADODB connection"); } $openstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".realpath($dbpath); $conn->open($openstr); $query = "SELECT * From authors"; $rs = $conn->execute($query); // Execute a SQL query and store the results // within recordset ?>
|