新闻动态

我们珍惜遇见的每一位客户,也感恩以往岁月里给与我们支持的每一位客户

php读取Access数据库并写入mysql数据库

<?php $conn = new com("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("11.mdb"); $conn->Open($connstr); $rs = new com("ADODB.RecordSet"); $rs->Open("select * from newslist where n_ppid=81",$conn,1,3); while(!$rs->eof) { $title=$rs->Fields(4); $neirong=$rs->Fields(8); $time=$rs->Fields(24); $laiyuan=$rs->Fields(10); $zuozhe=$rs->Fields(11); $sql=mysql_query("INSERT INTO mysql数据库名字(title,content,addtime,laiyuan,author)<br /> VALUES('".$title."','".$neirong."','".$time."','".$laiyuan."','".$zuozhe."')"); $rs->MoveNext(); } ?>

以上php读取Access数据库信息和录入mysql是不是没有错误呢?但是很多时候是导入不成功的,最常见的问题就是两个数据库的编码不同,怎么办呢,假如access数据库是gbk的,mysql数据库是utf8的,我们做以下操作即可:

<?php $conn = new com("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("11.mdb"); $conn->Open($connstr); $rs = new com("ADODB.RecordSet"); $rs->Open("select * from newslist where n_ppid=81",$conn,1,3); while(!$rs->eof) { $title=mb_convert_encoding($rs->Fields(4), 'utf-8','gb2312' ); $neirong=mb_convert_encoding($rs->Fields(8), 'utf-8','gb2312' ); $time=mb_convert_encoding($rs->Fields(24), 'utf-8','gb2312' ); $click=mb_convert_encoding($rs->Fields(12), 'utf-8','gb2312' ); $laiyuan=mb_convert_encoding($rs->Fields(10), 'utf-8','gb2312' ); $zuozhe=mb_convert_encoding($rs->Fields(11), 'utf-8','gb2312' ); $sql=mysql_query("INSERT INTO mysql数据库名字(title,content,addtime,laiyuan,author)<br /> VALUES('".$title."','".$neirong."','".$time."','".$laiyuan."','".$zuozhe."')"); $rs->MoveNext(); } ?>
西安网页设计

Vip定制

宏博网络,做网站、网站建设、开发、设计微信二维码

微信公众号

宏博网络,做网站、网站建设、开发、设计微信公众号

联系电话:029-81773686

VIP定制:18966895139(苏先生)

VIP 定制

电话

微信公众号

返回顶部