简体   繁体   English

通过PHP将数据从MSSQL最快传输到MySQL

[英]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; 我需要将数据从远程MS SQL数据库存储到本地MySQL数据库中。 I need to do this using PHP. 我需要使用PHP进行此操作。

The fetching of the data from MSSQL is simple enough: 从MSSQL提取数据非常简单:

SELECT orderRef
     , orderValue
  FROM remoteTbl

This results in 100k rows. 这将导致10万行。 I want to store this in a local MySQL database using PHP. 我想使用PHP将其存储在本地MySQL数据库中。 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. 但是,这对于10万行数据似乎是浪费的。

Is there some way I can do this more efficiently? 有什么办法可以更有效地做到这一点?

  • Updated further to comments: 进一步更新以评论:

  • by using the PHP resource from the MSSQL query perhaps? 通过使用来自MSSQL查询的PHP资源? I need to do things with the data, and the MSSQL DBMS is read only. 我需要处理数据,MSSQL DBMS是只读的。

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. 您可能应该使用mysqli,因为mysql功能将不再存在,但是要加快速度,您可以像这样执行一个大的insert语句。

$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) . ';');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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