它山之石可以攻玉

键盘上的生活
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

PHP读取ACCESS数据到MYSQL

Posted on 2011-05-10 16:26  陈达辉  阅读(1029)  评论(0编辑  收藏  举报

 

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

$sid=$_GET["sid"];
if ($sid==1){
 $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='装修课堂' and smallclassname<>''",$conn,1,3);
 while(!$rs->eof){
     switch ($rs->Fields[4]->value){
      case "装修顾问":
      $sclass=2;
      break;
      case "厨卫空间":
      $sclass=3;
      break;
      case "家具物语":
      $sclass=4;
      break;
      case "电器工程":
      $sclass=5;
      break;
      case "居饰风景":
      $sclass=6;
      break;
      case "材料广角":
      $sclass=7;
      break;
      default:
      $sclass=1;
     }

     $spic=$rs->Fields[6]->value;
     $user=$rs->Fields[7]->value;
     $hits=$rs->Fields[9]->value;
     if ($rs->Fields[24]->value==''){
      $comments=0;
     }else{
      $comments=$rs->Fields[24]->value;
     }
     $ytime=date("Y",strtotime($rs->Fields[8]->value));
     $mtime=date("m",strtotime($rs->Fields[8]->value));
     $dtime=date("d",strtotime($rs->Fields[8]->value));
     $stime=mktime(0,0,0,$mtime,$dtime,$ytime);
     $pfile=$stime."".rand(1000,9999).".shtml";

     //$sql="insert into rc_news_connent(n_title,n_content,n_bclass,n_sclass,n_pic,n_spic,n_user,n_time,n_hits,n_audit) values('".$rs->Fields[1]->value."','".$rs->Fields[2]->value."',1,".$sclass.",'','".$spic."','".$user."','".date("Y-m-d H:i:s")."',".$hits.",1)";
     $sql="insert into rc_news_connent(news_class,news_title,template_id,news_content,news_publisher,news_hits,created,inputtime,news_commentnum,news_image,news_file,news_htmlname) values(".$sclass.",'".$rs->Fields[1]->value."',1,'".$rs->Fields[2]->value."','admin',".$hits.",'".$stime."','".$rs->Fields[8]->value."',".$comments.",'".$spic."','".$rs->Fields[8]->value."','".$pfile."')";
     $result=mysql_query($sql);
     $rs->Movenext(); //将记录集指针下移
 }
 $rs->close();
 echo "成功!";
}else{
 echo "错误!";
}
?>