Code for converting a phpaccess database to a mysql database

Source: Internet
Author: User
The data collected by myself is ACCESS, but my program is mysql, so I wrote a program, and the program went three steps. I would like to share with my friends who like to operate the database. 1. connect to mysql with the following code: $ dbhostquot; l... the data collected by myself is ACCESS, but my program is mysql, so I wrote a program, and the program went three steps. I would like to share with my friends who like to operate the database.

1. connect to mysql with the following code:

$ Dbhost = "localhost: 3307"; // server $ db = "dataname"; // Database $ dbuser = "root "; // username $ dbpass = "********"; // password $ db_qianzhui = "sdb _"; // table prefix $ link = mysql_connect ($ dbhost, $ dbuser, $ dbpass); if (! $ Link) echo "link failed! "; Else echo" successful !!! "; Mysql_query (" set names 'utf8' "); mysql_query (" set character set UTF8 "); // >>> solve the problem of mysql_query ("SET CHARACTER_SET_RESULTS = utf8'"); // >>>> code mysql_select_db ("{$ db }");

2. connect to the access Database. the code is as follows:

$ Datapath = "data. mdb "; $ fenlei =" 101 "; $ conn = new com (" ADODB. connection "); $ connstr =" DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ = ". realpath ($ datapath); // Open source code phprm.com $ conn-> Open ($ connstr); $ rs = new com ("ADODB. recordSet "); $ rs-> Open (" select * from information where lanmu3id = 13 ", $ conn, 1, 1); // query *. in the MDB file

3. read and write operations as follows:

While (! $ Rs-> eof) {// $ f = $ rs-> Fields (1); // 1. assign values (* for debugging) // echo $ f-> value; // 2. check whether the code can be written (* for debugging). // assign values to the variables respectively. here, 'gb2312' and 'utf-8' are used to solve the garbled problem! $ Id = iconv ('gb2312', 'utf-8', $ rs-> Fields (ID)-> value); // ID is the access field, or use a number to represent $ name = iconv ('gb2312', 'utf-8', $ rs-> Fields (title)-> value ); $ jianjie = iconv ('gb2312', 'utf-8', $ rs-> Fields (1)-> value); $ content = iconv ('gb2312 ', 'utf-8', $ rs-> Fields (content)-> value); $ down = iconv ('gb2312', 'utf-8 ', $ rs-> Fields (download)-> value); echo "". $ name. "already inserted
"; // Output the insert record. // execute INSERT in sequence. The value is the variable $ SQL =" insert INTO 'shopex '. 'SDB _ article' ('article _ id', 'node _ id', 'title', 'content', 'uptime', 'ifpub', 'align ', 'filetype', 'filename', 'orderlist', 'disabled ') VALUES ('',' {$ fenlei} ',' {$ name }', '{$ info}', '123', '1', Null, Null, NULL, NULL, 'false ')"; //// the above is the SQL statement inserted into the MYSQL database //// mysql_query ($ SQL); // execute the statement !!! /// Echo $ rs-> Fields (name)-> value ."
"; $ Rs-> MoveNext (); /// an individual is used to convert a database from ACCESS to mysql ,}



Article URL:

Reprint ^ at will, but please attach the tutorial address.

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.