Access database quickly converted to MySQL database code

Source: Internet
Author: User
Tags mdb database access database
  code is as follows copy code

<?php
First, connect MySQL
$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 garbled problem
mysql_query ("SET Character_set_results=utf8 '");
mysql_select_db ("{$db}");
?>

The code is as follows Copy Code
<?php
Two, connect Access database
$datapath = "Data.mdb"; The MDB database name, which can be in other formats.
$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
?>

The code is as follows Copy Code

<?php
Third, the following preparation side read a write operation!
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 is an access field, or it is represented by 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> already inserted <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 ') ";
The above is the SQL inserted into the MySQL database

mysql_query ($sql); Execute the Statement!
echo $rs->fields (name)->value. "<br>";
$rs->movenext ();
Personal use for access to convert a database within MySQL
}
?>

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.