I've been studying PHP for the next two days, mainly in order to cope with learning Ajax need some background knowledge, I have an open source of things always have a sense of closeness, do not money things really everyone love ah because of the general space MySQL database must be paid to buy alone, so intend to use access for the time being, The results of a search data is the first big, the original PHP for each of the different database operation methods are not the same ... So search some blog, found many links access methods, but are not very satisfactory, finally find ADODB this dongdong. It's a class in PHP that has a built-in majority of the database operations you've seen. For example, PHP operations a MySQL is generally like this:
Copy Code code as follows:
$db = mysql_connect ("localhost", "root", "password");
mysql_select_db ("MyDB", $db);
$result = mysql_query ("SELECT * FROM Employees", $DB);
if ($result = = False) Die ("failed");
while ($fields = Mysql_fetch_row ($result)) {
For ($i =0, $max =sizeof ($fields); $i < $max; $i + +) {
Print $fields [$i]. ' ';
}
print "<br>n";
}
If you use ADODB, the following procedure gets the same result as
Copy Code code as follows:
Include ("adodb.inc.php");
$db = newadoconnection (' mysql ');
$db->connect ("localhost", "root", "password", "MyDB");
$result = $db->execute ("SELECT * FROM Employees");
if ($result = = False) Die ("failed");
while (! $result->eof) {
For ($i =0, $max = $result->fieldcount (); $i < $max; $i + +)
Print $result->fields[$i]. ' ';
$result->movenext ();
print "<br>n";
}
Then, if you want to use a different database, change the adoconnection connection name, and Access uses the
$db = newadoconnection (' access ');
The complete code is as follows:
Copy Code code as follows:
<?php
Include ("adodb/adodb.inc.php");
$db = adonewconnection (' access ');
$DSN = "Driver={microsoft Access Driver (*.mdb)};D Bq=d:\self\myphp\book.mdb; uid=; pwd=; ";
$db->connect ($DSN);
$result = $db->execute ("SELECT * from data");
if ($result = = False) Die ("failed");
while (! $result->eof) {
For ($i =0, $max = $result->fieldcount (); $i < $max; $i + +)
Print "<div style= ' border:1px solid #000000; ' > ". $result->fields[$i]." <br/> ";
$result->movenext ();
}
?>
ADODB can go here to download http://phplens.com/phpeverywhere/