php将access数据库转换到mysql数据库的方法_PHP

WBOY
Release: 2016-06-01 11:06:44
Original
769 people have browsed it

本文实例讲述了php将access数据库转换到mysql数据库的方法。分享给大家供大家参考。具体分析如下:

本人采集来的数据是ACCESS的,但我的程序是mysql的,故写了一个程序,程序三步走,分享一下,喜欢操作数据库的朋友应该都会用到的.

1.连接mysql,代码如下:

代码如下:

$dbhost="localhost:3307";//服务器 
$db="dataname";//数据库 
$dbuser="root";//用户名 
$dbpass="*******";//密码 
$db_qianzhui="sdb_";//表前缀 
$link=mysql_connect($dbhost,$dbuser,$dbpass); 
if(!$link) echo "链接失败!"; 
else echo "成功!!!"; 
mysql_query("SET NAMES 'UTF8'");
mysql_query("SET CHARACTER SET UTF8"); //>>>解决乱 
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");///////>>>码问题 
mysql_select_db("{$db}");


2.连接access数据库,代码如下:

代码如下:

$datapath="data.mdb"; 
$fenlei="101"; 
$conn = new com("ADODB.Connection"); 
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath($datapath);
$conn->Open($connstr); 
$rs = new com("ADODB.RecordSet"); 
$rs->Open("select * from information where lanmu3id=13 ",$conn,1,1); //查询*.MDB文件里面的


3.以下准备一边读一写入操作:

代码如下:

while(! $rs->eof) { 
//$f = $rs->Fields(1); //1.赋值(*调试用) 
//echo $f->value;   //2.看能不能写读出来(*调试用) 
//以下是分别给变量赋值,其中'gb2312','utf-8'为了解决乱码问题!
$id =iconv ('gb2312','utf-8',$rs->Fields(ID)->value);//ID为access字段,或用数字表示 
$name =    iconv ('gb2312','utf-8',$rs->Fields(title)->value); 
$jianjie = iconv ('gb2312','utf-8',$rs->Fields(1)->value); 
$content=  iconv ('gb2312','utf-8',$rs->Fields(content)->value); 
$down =    iconv ('gb2312','utf-8',$rs->Fields(download)->value); 
 
echo "".$name."已经插入
";//输出插入记录
///依次执行insert,值为变量
$sql="INSERT INTO `shopex`.`sdb_articles` (`article_id`,`node_id`,`title`,`content`,`uptime`,`ifpub`,`align`,`filetype`,`filename`,`orderlist`,`disabled`) VALUES ('','{$fenlei}','{$name}','{$info}','1275549287','1',Null,Null,NULL,NULL,'false')"; 
////以上是插入MYSQL数据库的SQL//////
mysql_query($sql); //执行语句!!! 
///echo $rs->Fields(name)->value. "
"; 
$rs->MoveNext(); 
/////个人用于ACCESS向mysql内转换数据库的操作,
}

希望本文所述对大家的php程序设计有所帮助。

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template