PHP准备声明问题

时间:2014-01-23 10:55:33

标签: php prepared-statement

我收到致命错误:无法通过第4行中的引用传递参数3 请建议我解决方案我希望绑定部分动态。

$values = array($username,$password);
$query = "select * from users where email_id = ? and password = ?"
$this->con = new mysqli('localhost', 'username', 'password','dbname');
$stmt = $this->con->prepare($query);
$count = 0;
for ($i = 0; $i < count($values); $i++) {
    $stmt->bind_param(++$count,$values[$i], PDO::PARAM_STR,12);
}
if ($stmt->execute()) {
    while ($row = $this->stmt->fetch()) {
       $data[] = $row;
    }
    return $data;
} else {
    return null;
}

1 个答案:

答案 0 :(得分:1)

使用bindValue()

$stmt->bindValue(++$count,$values[$i], PDO::PARAM_STR,12);