PHP code _ PHP Tutorial for reading ACCESS data to MYSQL

Source: Internet
Author: User
Tags mysql tutorial
PHP code for reading ACCESS data to MYSQL. The following example is relatively simple. you can use the com interface to read the access database tutorial, read the data, and then connect to the mysql tutorial database, insert the corresponding field into the mysql table and the instance below the field is relatively simple, that is, first use the com interface to read the access database tutorial, read the data and then connect to the mysql tutorial database, insert the corresponding field to the table and field corresponding to mysql.

Header ('ontent-Type: text/html; charset = GB2312 '); // avoid output garbled characters
$ Dbhost = "localhost ";
$ Dbuser = "root ";
$ Dbpassword = "123456 ";
$ Dbname = "139 miaosha ";
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 class'", $ conn, 1, 3 );
While (! $ Rs-> eof ){
Switch ($ rs-> Fields [4]) {
Case "decoration consultant ":
$ Sclass = 1;
Break;
Case "kitchen space ":
$ Sclass = 2;
Break;
Case "furniture Story ":
$ Sclass = 3;
Break;
Case "electrical engineering ":
$ Sclass = 4;
Break;
Case "decoration scenery ":
$ Sclass = 5;
Break;
Case "wide angle material ":
$ 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 ();
?>

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.