【问题标题】:Number of variables doesn't match number of parameters in prepared statements变量的数量与准备好的语句中的参数数量不匹配
【发布时间】:2015-04-01 12:08:13
【问题描述】:
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '?'";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $database);
$stmt->execute();
$resultSet = $stmt->get_result();

上面写着“警告:mysqli_stmt::bind_param():变量的数量与准备好的语句中的参数数量不匹配......”

有人可以解释什么是错的吗? $database 是一个字符串。

【问题讨论】:

  • 您必须删除问号周围的单引号。在准备好的语句中没有必要。

标签: php mysql mysqli


【解决方案1】:

如果您使用? 作为占位符,请不要使用刻度' s

$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param('s', $database);
$stmt->execute();
$resultSet = $stmt->get_result();

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 2020-10-27
    • 2016-05-02
    • 1970-01-01
    • 2014-03-07
    • 2016-01-23
    • 2022-05-27
    • 2021-06-08
    相关资源
    最近更新 更多