欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP读取ACCESS数据到MYSQL的代码

程序员文章站 2022-12-26 10:54:54
复制代码 代码如下:
复制代码 代码如下:

<?php
header('ontent-type:text/html;charset=gb2312');//避免输出乱码
$dbhost ="localhost";
$dbuser ="root";
$dbpassword = "123456";
$dbname = "139miaosha";
mysql_connect($dbhost,$dbuser,$dbpassword) or die("error!");
mysql_query("set names 'gbk'");
mysql_select_db('139miaosha');
$conn = new com("adodb.connection");
$connstr="driver=microsoft access driver (*.mdb);dbq=f:/wamp/www/miaosha/ruichao858.mdb";
$conn->open($connstr);
$rs = new com("adodb.recordset");
$rs->open("select * from news where bigclassname='装修课堂'",$conn,1,3);
while(!$rs->eof){
switch ($rs->fields[4]){
case "装修顾问":
$sclass=1;
break;
case "厨卫空间":
$sclass=2;
break;
case "家具物语":
$sclass=3;
break;
case "电器工程":
$sclass=4;
break;
case "居饰风景":
$sclass=5;
break;
case "材料广角":
$sclass=6;
break;
default:
$sclass=1;
}
if ($rs->fields[6]){
$spic="";
}else{
$spic=$rs->fields[6];
}
if ($rs->fields[7]){
$user="";
}else{
$user=$rs->fields[7];
}
if ($rs->fields[9]){
$hits=1;
}else{
$hits=$rs->fields[9];
}
$sql="insert into rc_news(n_title,n_content,n_bclass,n_sclass,n_pic,n_spic,n_user,n_hits,n_audit) values('".$rs->fields[1]."','".$rs->fields[2]."',1,".$sclass.",'','".$spic."','".$user."',".$hits.",1)";
$result=mysql _query($sql);
//echo $rs->fields[1];
//echo "<br/>";
$rs->movenext(); //将记录集指针下移
}
$rs->close();
?>