在opencart中,当表中存在记录时,SELECT查询会给出一个空结果


In opencart, a SELECT query gives an empty result when record is present in table

我使用PHP"fgetcsv"函数读取了一个CSV文件,并将CSV中的产品添加/更新到我的opencart存储中。为此,我必须检查产品是否存在。

我已经编写了以下函数来检查我的模型中是否存在产品:

function existProduct($searchValue)
{       
    $sql ="SELECT `product_id` FROM ".DB_PREFIX."product WHERE `model`='".$searchValue."'"; 
    $result2 = $this->db->query($sql);
    if ($result2->num_rows > 0)
    {
        return $result2->row['product_id'];
    }
    return false;
}

并以以下方式调用控制器:

$productID = $this->model_tool_cust_import->existProduct($searchValue);

当产品表中存在产品时,它会返回一个空结果,但如果我用单引号传递字符串值,它就会起作用,例如'YS16034137':

 $productID = $this->model_tool_cust_import->existProduct('YS16034137');

我尝试使用trim,但没有成功。

当使用var_dump($searchValue)时,我得到了以下输出:

string 'Y�S�1�6�0�3�4�1�3�7' (length=19)

同样,当我尝试echo $searchValue ;时,我得到了输出YS16034137

当我从csv中读取列值时,我得到了它的解决方案,它在字符串中的每个字符之间添加了"null character"(''0)。我不知道它来自哪里,但我使用str_replace("''0",",$value)从字符串中删除了null字符,然后它对我有效,谢谢。