PHP读取ACCESS数据到MYSQL的代码
前端之家收集整理的这篇文章主要介绍了
PHP读取ACCESS数据到MYSQL的代码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="codetitle"><a style="CURSOR: pointer" data="90214" class="copybut" id="copybut90214" onclick="doCopy('code90214')"> 代码如下:
<div class="codebody" id="code90214">
<?
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]."',".$sclass.",'','".$spic."','".$user."',".$hits.",1)";
$result=
MysqL _query($
sql);
//echo $rs->Fields[1];
//echo "
";
$rs->Movenext(); //将记录集指针下移
}
$rs->close();
?>