书上写得是按照以下代码完成对ACCESS数据库的操作: require_once 'adodb/adodb.inc.php'; $conn = NewADOConnection ( access ); $connstr = Driver={Microsoft Access Driver (*.mdb)};DBQ= . realpath ( database/testDB.mdb ) . ;Uid=;Pwd=;; $conn-Conn
书上写得是按照以下代码完成对ACCESS数据库的操作:
require_once 'adodb/adodb.inc.php';
$conn = NewADOConnection ( "access" );
$connstr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" . realpath ( "database/testDB.mdb" ) . ";Uid=;Pwd=;";
$conn->Connect($connstr);
$sql = "select * from productClass";
$rs = $conn->execute ( $sql );
print_r($rs->GetRows());
但是,从数据库中读取的中文居然都是乱码。解决方法就是把代码改成如下形式:
require_once 'adodb/adodb.inc.php';
$conn = new COM ( "ADODB.Connection", NULL, 65001) or die ( "ADO connect failed!" );
$connstr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" . realpath ( "database/testDB.mdb" ) . ";Uid=;Pwd=;";
$conn->open ( $connstr );
$sql = "select * from productClass";
$rsArr = $conn->execute ( $sql );
if ($rsArr) {
while ( ! $rsArr->eof ) {
echo $rsArr->fields["id"]." ".$rsArr->fields["className"]."
";
$rsArr->MoveNext();
}
} else {
print $conn->ErrorMsg ();
}
$rsArr = null;
$conn->close ();
$conn = null;