Home > php教程 > php手册 > PHP通过ADODB操作ACCESS数据库,中文乱码的解决办法

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

WBOY
Release: 2016-06-06 19:58:08
Original
2157 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template