$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";
}
如果使用ADODB, 那么以下程序得到的结果同上
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";
}
然后, 如果要使用其它数据库,改变一下ADOConnection的连接名就是了, ACCESS就用
$db = NewADOConnection('access');
完整代码如下:
<?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 "<div style='border:1px solid #000000;'>".$result->fields[$i]." <br />";
$result->MoveNext();
}
?>
ADODB可以到这里去下载 http://phplens.com/phpeverywhere/
-----正文到此结束-----
发表评论 取消回复