在我们迁移到速度更快的debian linux服务器之前,这个例程一直有效。这是一段代码片段,用于读取csv文件,并在不存在具有相同manufacturers_name的其他记录时将记录插入到表中。发生的事情是插入第一条记录,当找到另一条记录时,执行函数找不到前一条插入的记录,并添加该记录而不是更新。如果我在没有清空表的情况下第二次运行相同的例程,那么所有的记录都会被找到,并且只会进行更新。我想可能是速度的问题,所以我尝试在这个过程中加入睡眠,但它没有任何影响。有什么想法吗?谢谢
while (($data = fgetcsv($handle, 0, chr(9),chr(0))) !== FALSE) {
****** Setup stuff here *******
$msql_data_array = array('manufacturers_name' => $data[$manufacturer_sn]);
$sql = "select count(*) as total,manufacturers_id,manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_name = \"" . $data[$manufacturer_sn] . "\"";
$manufacturers = $db->Execute($sql);
if ($manufacturers->fields['total'] == 0) { <<<<<<<<<<<< This always returns 0 even if the record was just added by the previous operation(s)
***** Inserts a new record ******
} else {
***** Updates the current record *******
}
]发布于 2016-01-02 08:22:19
这看起来像一个简单的.csv导入。您可以将PHP代码替换为命令行MySQL调用,如下所示:
字段mysqlimport --由'\t‘db_name import.csv终止
https://stackoverflow.com/questions/34561144
复制相似问题