我有一个查询,看起来像这样:MySQL:错误,当查询返回没有结果?
SELECT number
FROM table1
INNER JOIN table2
WHERE name = 'stack_overflow' AND table1.id = table2.id
AND user_id = 5
这将返回一个数字。它做的是正确的事情,但是当名字内部传递一个不存在于db中的名字时,PHP给了我一个错误。这是我正在执行它:
$stmt = $this->db->prepare($sql);
$stmt->execute();
$x = $stmt->fetchColumn();
我总是得到正确的$ x值当名称的表存在,但是当它不,我得到以下错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name_that_is_not_in_table'
不知道....
显示导致此错误的实际查询。 –
什么是'name_that_is_not_in_table'?它是否包含任何可能破坏查询的特殊字符? –
不是......这是一个普通的字符串,它不存在,我执行查询,它只是返回没有值 – luqita