Home >Backend Development >PHP Tutorial > php操作access数据解决方法

php操作access数据解决方法

WBOY
WBOYOriginal
2016-06-13 13:12:19857browse

php操作access数据
我这里有一个access数据文件db.mdb,我现在要将他的数据转化为mysql数据。那么用php如何才能操作这个db.mdb。我只需要读取就好了,然后将读取的信息插入我建的mysql数据库。那位有做过,感激!

------解决方案--------------------
$mdb = "库名.mdb";
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath($mdb) ;
$conn = odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );

$rs = odbc_exec($connid,"select * from 表名");
while($row = odbc_fetch_array($rs)) {
//这里已经可以直接使用了,不一定非要转到 mysql
$row = array_map('addslashes', $row); //转义特殊字符
mysql_query("insert into 表名 values ('" . join("','", $row) ."')"; //插入mysql表
}

Statement:
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