欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP通过ADODB操作ACCESS数据库,中文乱码的解决办法

程序员文章站 2024-02-06 16:41:04
...

书上写得是按照以下代码完成对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;