Home >Backend Development >PHP Tutorial >Convert mssql data to mysql
1. I work for a small company. My daily job is to maintain the normal operation of the website, correct small bugs in the website, and cooperate with every "eureka" idea of the boss. Today, the boss needs to move the original ASP website to In the newly purchased php system, two problems arose
1. Convert the mssql database into mysql
2. Rewrite the field contents in some tables into the new system table fields
2.
Convert mssql database to mysql. There are ready-made tools, so this step is relatively simple. The tool I use is mss2sql. Baidu’s writing speed was too slow before using it. After my own testing (after my own use) It is indeed very slow. Students with large databases are advised not to use it.) During the process, I encountered a table that could not be converted, so I opened the table to view and found that the content of a field existed. After comparing with the new system, this field should be discarded, so Replace the full text, try it again, and it's done.
Next, I will compare the imported database tables with the new system database tables, discard some unused tables, export useful tables, and insert them into the new system database.
Okay, so far everything is going relatively smoothly
Next, without introducing a framework, I wrote a PHP program to help me insert the contents of the old database into the corresponding table of the new database.
First
$mysql_server_name=""; //Database server name
$mysql_username=""; // Username to connect to the database
$mysql_password=""; // Password to connect to the database
$mysql_database="" ; // The name of the database
// Connect to the database
$c $mysql_username,$mysql_password);
// SQL statement to extract information from the table
$strsql="SELECT * from {table name} where {query conditions} ";
// 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);
//Translate special characters
$row['field name']=addslashes($row['field name' ]);//Some fields contain special characters such as single quotes and double quotes that need to be translated
//Synthetic query statements (since the new system is associated with multiple tables, the statements must be split)
$strsql="INSERT INTO ` Table name ` VALUES (Field value (must correspond, and be sure to add single quotes. I have been stuck here for a long time. It seems that everything is right, but it cannot be executed, because the single quotes are missing))";
$strsql1="insert into { Table name} (field name) values (field value')";
//echo($strsql);
// Execute sql query
$result1=mysql_query($strsql1, $conn);
$next=mysql_query($ strsql, $conn);
var_dump($num++);
}
// Release resources
mysql_free_result($result);
// Close connection
mysql_close($conn);
echo "Execution completed"; // Due to php I can't observe the execution process, so I added the end mark
Since then, the work has been repeated. If there are any omissions or mistakes in my knowledge, I hope the experts can criticize and correct them. Thank you
The above has introduced the corresponding conversion of mssql data to mysql, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.