简体   繁体   中英

Fastest transfer of data from MSSQL to MySQL via PHP

I need to store data from a remote MS SQL db into a local MySQL db; I need to do this using PHP.

The fetching of the data from MSSQL is simple enough:

SELECT orderRef
     , orderValue
  FROM remoteTbl

This results in 100k rows. I want to store this in a local MySQL database using PHP. Simply enough, I can do (with the addition of another field I want) :

while(list($orderRef, $orderValue) = mssql_fetch_array($result)){

mysql_query("INSERT INTO localTbl (orderRef, orderValue, updated)
                           VALUES ('$orderRef', '$orderValue', NOW())");

} // done all rows

This seems wasteful for 100k rows of data though.

Is there some way I can do this more efficiently?

  • Updated further to comments:

  • by using the PHP resource from the MSSQL query perhaps? I need to do things with the data, and the MSSQL DBMS is read only.

Thanks

You should probably use mysqli since mysql functions aren't going to be around any more but to speed this up you could do one big insert statement like so.

$sql = "INSERT INTO localTbl (orderRef, orderValue, updated) VALUES ";

while(list($orderRef, $orderValue) = mssql_fetch_array($result)){

    $sql_rows[] = "('$orderRef', '$orderValue', NOW())";

}

mysql_query($sql . implode(',', $sql_rows) . ';');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM