How PHP transforms an Access database to a MySQL database _php tips

Source: Internet
Author: User
Tags access database

This example describes how PHP transforms an Access database to a MySQL database. Share to everyone for your reference. The specific analysis is as follows:

I collected the data is access, but my program is MySQL, so wrote a program, the program three steps to share, like the operation of the database friends should be used.

1. Connect MySQL, code as follows:

Copy Code code as follows:
$dbhost = "localhost:3307";//server
$db = "Dataname";//Database
$dbuser = "root";//user name
$dbpass = "*******";//Password
$db _qianzhui= "sdb_";//Table Prefix
$link =mysql_connect ($dbhost, $dbuser, $dbpass);
if (! $link) echo "link failed!";
else echo "Success!!!";
mysql_query ("SET NAMES ' UTF8 '");
mysql_query ("Set CHARACTER set UTF8"); >>> Solve Chaos
mysql_query ("SET Character_set_results=utf8 '");///////>>> code problem
mysql_select_db ("{$db}");

2. Connect to the Access database with the following code:
Copy Code code as follows:
$datapath = "Data.mdb";
$fenlei = "101";
$conn = new COM ("ADODB. Connection ");
$connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ($datapath);
$conn->open ($CONNSTR);
$rs = new COM ("ADODB. RecordSet ");
$rs->open ("SELECT * from information where lanmu3id=13", $conn, 1, 1); Query *. MDB file inside the

3. The following is prepared to read a write operation:
Copy Code code as follows:
while (! $rs->eof) {
$f = $rs->fields (1); 1. Assign Value (* Debugging use)
Echo $f->value; 2. See if you can read it (* Debug)
The following is assigned to the variable value, where ' gb2312 ', ' utf-8 ' to solve the garbled problem!
$id =iconv (' gb2312 ', ' utf-8 ', $rs->fields (ID)->value);//id as an access field, or with 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 "<font color=red>". $name. " </font> Insert <br>//output Insert Record
The insert is executed sequentially, and the value is a variable
$sql = "INSERT into ' Shopex '. ' Sdb_articles ' (' article_id ', ' node_id ', ' title ', ' content ', ' uptime ', ' ifpub ', ' align ', ') ' FileType ', ' filename ', ' orderlist ', ' disabled ') VALUES (', ' {$fenlei} ', ' {$name} ', ' {$info} ', ' 1275549287 ', ' 1 ', Null, Null,null,null, ' false ') ";
Above is the sql//////that inserts MySQL database
mysql_query ($sql); EXECUTE statement!!!
echo $rs->fields (name)->value. "<br>";
$rs->movenext ();
Personal use for access to convert databases within MySQL,
}

I hope this article will help you with your PHP program design.

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.