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.