复制代码 代码如下:
$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";
}
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";
}
$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();
}
?>
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/
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!