【发布时间】:2013-10-02 21:50:28
【问题描述】:
我有一个脚本可以读取 XML 文件并将数据插入 mysql 数据库。我的问题是它只插入一条记录,我要插入 60 000 行数据,我希望它比花一个小时插入行更快。
我的脚本
$db_link = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('my_db');
//SIMPLEXML: Cleaned file is opened
$xml_source='cleanme.xml';
$xml=simplexml_load_file($xml_source);
//Reading each tag in the xml file
foreach($xml->Property as $prop){
echo 'Reference '.$prop->Reference.'<br>';
$ref_id=$prop->Reference;
//Reading sub tags in the xml file
foreach($prop->Images->Image as $chk)
{
echo 'REF_ID '.$ref_id.' '.'ImageID '.$chk->ImageID.'<br>';
$sql_refid = $ref_id;
$sql_link =$chk->ImageID;
//Inserts data into to the database
$sql.="INSERT INTO prop_ref (id, ref, link) VALUES (NULL, '{$sql_refid}','{$sql_link}')";
}
}
mysql_query($sql);
echo 'Complete';
【问题讨论】:
-
你用的是什么版本的MYSQL?你考虑过 MariaDB 和 ARIA 引擎吗?