Home > Article > Backend Development > PHP code to read ACCESS data to MYSQL_PHP tutorial
The following example is relatively simple, that is, first use the com interface to read the access database tutorial, read the data, then connect to the mysql tutorial database, and insert the corresponding fields into the corresponding tables and fields of mysql.
header('ontent-Type:text/html;charset=GB2312');//Avoid garbled code output
$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='Decoration Classroom'",$conn,1,3);
while(!$rs->eof){
Switch ($rs->Fields[4]){
case "Renovation Consultant":
$sclass=1;
break;
case "Kitchen and Bathroom Space":
$sclass=2;
break;
case "Furniture Story":
$sclass=3;
break;
case "Electrical Engineering":
$sclass=4;
break;
case "Home Decoration Scenery":
$sclass=5;
break;
case "Material wide angle":
$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 "
";
$rs->Movenext(); //Move the record set pointer down
}
$rs->close();
?>