Convert MSSQL data corresponding to MySQL

Source: Internet
Author: User
Tags closing tag
I worked in a small company, daily work is to maintain the normal operation of the site, rewrite the site of small bugs, as well as with the boss of each "epiphany" creativity, today the boss needs to move the original ASP's website to the newly purchased PHP system, resulting in 2 problems

1. Convert the MSSQL database to MySQL

2. Re-write the contents of the fields in some tables into the New system table field

Two.

The MSSQL database into MySQL, there are ready-made tools, so this step is relatively simple. I use the tool is Mss2sql, with the previous Baidu write speed too slow, after I test (after I use really very slow, advised the database is very large classmate, do not use) Encountered in the process there is a table can not be converted, so I opened the table to view, found that a field of content exists ★, after comparison of the new system this field should be discarded, and then replace the full text, again, to fix.

Next I will import the good database table in the database of the new system against the table, discard some unused tables, export the useful tables, and insert into the database of the new system.

Okay, so far, everything's going well.

Next, without introducing the framework, I wrote a PHP program myself to help me insert the contents of the old database into the corresponding table of the new database.

First of all

$mysql _server_name= "";//Database server name
$mysql _username= ""; Connect to database user name
$mysql _password= ""; Connect Database Password
$mysql _database= ""; The name of the database

Connecting to a database
$c $mysql _username, $mysql _password);

SQL statement that extracts information from a table
$strsql = "SELECT * from {table name} where {query condition} ";
Execute SQL query
mysql_select_db ($mysql _database, $conn);
$result =mysql_query ($strsql, $conn);
Get query Results

$num = 0;
while ($row = Mysql_fetch_array ($result)) {
Var_dump ($row);
Translating special characters
$row [' Field name ']=addslashes ($row [' field name ']);//Some fields contain single quotes, double quotes, etc. special characters need to be translated
Composition Query Statement (splitting a statement because the new system is associated with multiple tables)
$strsql = "INSERT into ' table name ' values (the field value (must correspond, and note the addition of single quotation marks, I have been stuck here for a long time clearly feel all right but just can't execute, is missing single quotes))";
$strsql 1= "insert into {table name} (field name) VALUES (field value ')";
Echo ($strsql);
Execute SQL query
$result 1=mysql_query ($strsql 1, $conn);
$next =mysql_query ($strsql, $conn);
Var_dump ($num + +);
}
Freeing resources
Mysql_free_result ($result);
Close connection
Mysql_close ($conn);
echo "Done";//Because PHP cannot observe the execution process, I added the closing tag

Since then, the work is repeated, I caishuxueqian if there is any omission, or wrong, I hope the great God can criticize correct, thank you Home

The above describes the MSSQL data corresponding to the conversion to MySQL, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.