Code for quickly converting an access database to a mysql database

Source: Internet
Author: User
Tags mdb database
Only pay attention to fields and database types for conversion.

Only pay attention to fields and database types for conversion.

The Code is as follows:

// 1. Connect to mysql
$ Dbhost = "localhost: 3307"; // server
$ Db = "dataname ";//
$ Dbuser = "root"; // User Name
$ 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 garbled Problem
Mysql_query ("SET CHARACTER_SET_RESULTS = utf8 '");
Mysql_select_db ("{$ db }");
?>

The Code is as follows:
// 2. Connect to the access Database
$ Datapath = "data. mdb"; // MDB database name, which can be in another format.
$ Fenlei = "101 ";
$ Conn = new com ("ADODB. Connection ");
$ Connstr = "DRIVER = {Microsoft Driver (*. mdb)}; DBQ =". realpath ($ datapath );
$ Conn-> Open ($ connstr );
$ Rs = new com ("ADODB. RecordSet ");
$ Rs-> Open ("select * from information where lanmu3id = 13", $ conn,); // query
?>

The Code is as follows:

// 3. Read and Write operations on one of the following!
While (! $ Rs-> eof ){
// $ F = $ rs-> Fields (1); // 1. assign a value (* for debugging)
// Echo $ f-> value; // 2. Check whether it can be written or read (* for debugging)
// Assign values to the variables respectively. 'gb2312' and 'utf-8' are used to solve the garbled problem!
$ Id = iconv ('gb2312', 'utf-8', $ rs-> Fields (ID)-> value); // ID is an access field, or a number
$ 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 insert record

// Execute insert in sequence and the value is a 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 preceding is the SQL statement used to insert a MYSQL database.

Mysql_query ($ SQL); // execute the statement!
/// Echo $ rs-> Fields (name)-> value ."
";
$ Rs-> MoveNext ();
// Personal operation for converting ACCESS to mysql database
}
?>

Related Article

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.