I have been studying PHP for the past two days, mainly to cope with some background knowledge required to learn AJAX. I always have an inexplicable affinity for open source things. Everyone loves free things. Because of the general spatial MYSQL database You have to spend money to buy it separately, so I planned to use ACCESS for the time being, but when I checked the information, I was confused. It turned out that PHP operates different methods for different databases... So I searched some blogs and found many links. ACCESS methods, but none of them are satisfactory, and finally I found ADODB. It is a class of PHP that has built-in most of the database operation methods you have seen. For example, when PHP operates a MYSQL, it is usually Like this:
Copy code The code is 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 "
n";
}
If you use ADODB, the results obtained by the following program are the same as above
Copy code The code is 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 "
n";
}
Then, if you want to use other databases, just change the connection name of ADOConnection. For ACCESS, use
$db = NewADOConnection ('access');
The complete code is as follows:
Copy code The code is as follows:
< ?php
include("adodb/adodb.inc.php");
$db = ADONewConnection('access');
$dsn = "Driver={Microsoft Access Driver (*.mdb)} ;Dbq=d:selfmyphpbook.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 "
".$result->fields[ $i]."
";
$result->MoveNext();
}
?>
ADODB can be downloaded here http://phplens.com/phpeverywhere/
http://www.bkjia.com/PHPjc/317534.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317534.htmlTechArticleI have been studying PHP these two days, mainly to cope with some background knowledge needed to learn AJAX. I am interested in open source There is always an inexplicable feeling of closeness to things that are free of charge, and everyone loves them because...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn