Glover logo

On Line Databases

 Index

Home Glovers Contact Form

Pegasus Mail

Pegasus Mail Pmail Features

Pmail Extensions

Populist Delphi (1) Delphi (2) Dos Email

Digital Cameras

Digital images Renumber images Slideshows

Databases

Online Databases Access & ASP Access & PHP Mysql & ASP Mysql & PHP

Connection to MS Access databases - PHP scripting

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.

<HTML> <HEAD><TITLE>Simple ADO Query</TITLE></HEAD> <BODY BGCOLOR="White" topmargin="10" leftmargin="10"> <!-- Display Header --> <font size="4" face="Arial, Helvetica"> <b>Simple ADO Query with PHP</b></font><br /> <hr size="1" color="#000000" /> Contacts within the Authors Database:<br><br> < ?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 ?> <TABLE border = 1><tr bgcolor = '#DDEEAA'><th>ID</th><th>Author</th> <th>Year Born</th></tr> < ?php $columns = $rs->Fields->Count(); $rowcount = 0; while (!$rs->EOF) { echo "<tr bgcolor = '#CCEEFF'>"; for($i=0; $i < ($columns); $i++) { $fld[$i] = $rs->Fields($i); echo "<TD VAlign=top>" .$fld[$i]->value ."</TD>"; } echo "</tr>"; $rowcount++ ; $rs->MoveNext(); } ?> </TABLE> < ?php echo "Rowcount= " .$rowcount; $rs->Close(); $conn->Close(); $rs = null; $conn = null; ?> </BODY></HTML>

   Demo: Example of above code