COUNT(..)无效的简单预备语句

时间:2017-04-19 10:47:49

标签: mysql

我使用以下预准备语句代码收到以下错误。想知道原因是什么,因为它看起来都是正确的。

Notice: Connection failed: Prepared statement invalid: Operand should contain 1 column(s) in C:\xampp\htdocs\index.php on line 58

以下是代码:

$conn = new mysqli('localhost', 'root', '', 'myusers'); // this is confirmed to work for connecting
// Check connection
if ($conn->connect_error) {
    trigger_error('Connection failed: ' . $conn->connect_error);
    die();
}
$stmt = $conn->prepare('SELECT COUNT(id) as count_u FROM Users WHERE (title=?, forename=?, surname=?)');
if (!$stmt) { // here, $stmt is false or such.
    trigger_error('Connection failed: Prepared statement invalid: ' . htmlspecialchars($conn->error));
    die();
}

2 个答案:

答案 0 :(得分:1)

使用

WHERE title=?
  AND forename=?
  AND surname=?

答案 1 :(得分:0)

使用和/或在你的where子句

$stmt = $conn->prepare('SELECT COUNT(id) as count_u FROM Users WHERE title=? and/or  forename=? and/or surname=?)');
$stmt->bind_param("sss", $title, $forename, $surname);
相关问题