The method of using ADODB to make PHP operate an Access database _php the basics

Source: Internet
Author: User
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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.