MySQL Execute在上一次插入记录后查询失败


MySQL Execute fails query after insert of record on previous pass

在我们转移到速度更快的debian-linux服务器之前,这个例程一直有效。这是一段代码,用于读取csv文件,并在不存在具有相同manufacturer_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 *******
    }
]

这看起来像一个简单的.csv导入。您可以用命令行MySQL调用来替换PHP代码,如下所示:

mysqlimport--由"''t''t"db_name import.csv 终止的字段

参考编号:http://dev.mysql.com/doc/refman/5.7/en/mysqlimport.html