PHP讀取ACCESS資料到MYSQL

來源:互聯網
上載者:User

 

<?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 "錯誤!";
}
?>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.