PHP读取ACCESS数据到MYSQL的代码

 2025-01-15  阅读 375  评论 8  点赞 254

摘要:复制代码 代码如下:
复制代码 代码如下:

<?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();
?>


标签:phpphp教程

评论列表:

显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2460
  • 积分67666
  • 金币86666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0274秒, 内存占用1.94 MB, 访问数据库31次

冀ICP备19034377号