1.咕~~(╯﹏╰)b 各种乱码。
2.本来是MFC+Access 用msado15.dll写的系统,闲的想用php改改。
Demo.php
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 结果:<br> <?php require_once 'ADOConn.php'; $ADOConnObj = new ADOConn(); //$ADOConnObj->OnInitADOConn(); $sql="select id,sccoun,cpname,cpip,dwname,[memo] from z_sc where id=3 or id=4 or id=5"; $ADOConnObj->GetRecordSet($sql); $sql="select id,sccoun,cpname,cpip,dwname,[memo] from z_sc where sccoun='成都'"; $ADOConnObj->GetRecordSet($sql); /* "update z_sc set cpname='%s',[memo]='%s' ,cpip='%s',dwname='%s',cpmodel='%s',cpno='%s',snno='%s', sperson='%s',sphone='%s',azdate='%s' where ID=%d ", "insert into z_sc(sccoun,cpname,dwname,[memo],cpip,cpmodel,cpno,snno,sperson,sphone,azdate) "delete from z_sc where ID=%d " */ $sql="update z_sc set [memo]='已修改' where id=3 " ; $ADOConnObj->ExecuteSQL($sql); echo "</br>"."over...."; ?>
*ADOConn.php
<?php class ADOConn { public function OnInitADOConn() { //读取mdb数据库例程1.连接数据库 --完全没用到这个函数 $conn = new com("ADODB.Connection") or die ("创建数据库连接失败!"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=**; DBQ=". realpath("D:/AppServ/www/php_access/PhoSys.mdb"); $conn->Open($connstr); /*方法二 D:AppServApache2.2PhoSys.mdb $connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PhoSys.mdb;Persist Security Info=False;Jet OLEDB:Database Password=hzcjy"; */ /*方法三 解决乱码 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 = new com("ADODB.Connection") or die ("创建数据库连接失败!"); //乱码这个不管用,下边管用 $conn->exec("set names utf8"); */ } //函数主要用于打开并获得记录集 public function GetRecordSet($query) { $conn = new COM ( "ADODB.Connection", NULL, 65001) or die ( "ADO connect failed!" ); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=hzcjy; DBQ=". realpath("D:/AppServ/www/php_access/PhoSys.mdb"); $conn->Open($connstr); $rs=$conn->Execute($query); $row="0"; if($rs){ while(!$rs->EOF) { $string =""; for ($i=0;$i<$rs->Fields->count;$i++) { if ($i==0) { $string.=$rs->Fields($i)->Value; continue; } $string.='|'.$rs->Fields($i)->Value; } $string.=" "."<br>"; if ($row==300) { break; } $row++; echo " "; echo $string; $rs->MoveNext(); } }//end if else { print $conn->ErrorMsg ();} $rs = null; $conn->close (); $conn = null; } public function ExecuteSQL($query) {//执行数据库语句 delete,update, //--OnInitADOConn(); $conn = new COM ( "ADODB.Connection", NULL, 65001) or die ( "ADO connect failed!" ); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=hzcjy; DBQ=". realpath("D:/AppServ/www/php_access/PhoSys.mdb"); $conn->Open($connstr); $result =$conn->Execute($query); if($result) echo "successful"; else { $conn->ErrorMsg();echo "failed"; } $rs = null; $conn->close (); $conn = null; } } ?>
结果
资料:
3.http://www.cnblogs.com/jukan/p/5633705.html
php连接Access数据库的三种方法
(1).
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" .
realpath("test.mdb");
$conn->Open($connstr);
(2).
$conn=new com("ADODB.connection");
$connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".realpath
("test.mdb");
$conn->open($connstr);
(3).
$connection = odbc_connect("Driver={Microsoft Access Driver
(*.mdb)};Dbq=$mdbFilename", $user, $password);
4.https://sjolzy.cn/Operation-of-a-simple-PHP-class-Access.html
一个简洁的PHP操作Access类
5.【非常棒】PHP通过ADODB操作ACCESS数据库,中文乱码的解决办法
http://blog.csdn.net/dengwei4378/article/details/7103377?locationNum=1&fps=1
厄 先备注着,有空的时候过来写写总结和经验。over