PHP bindParam()函数有多个参数

时间:2014-03-28 12:12:49

标签: php pdo sqlbindparameter

是什么人,

我有以下代码:

$selectUserQuery = 'SELECT email_address, password FROM user WHERE email_address = :email_address AND password = :password';
$prepSelectUser = $conn->prepare($selectUserQuery);
/*
* HOW DO I ADD MULTIPLE PARAMETERS TO THIS BINDPARAM() FUNCTION?
*/
$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_INT);
$prepSelectUser->execute();
$userResult = $prepSelectUser->fetchAll();
$userCount = count($userResult);

如何向bindParam()函数添加多个参数?

2 个答案:

答案 0 :(得分:5)

你根本不需要这个功能。以及您使用的大多数其他代码。

$sql  = 'SELECT 1 FROM user WHERE email_address = ? AND password = ?';
$stmt = $conn->prepare($sql);
$stmt->execute([$email, $password]);
$userCount = $stmt->fetchColumn();

答案 1 :(得分:1)

首先,改变

$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_INT);

$prepSelectUser->bindParam(':email_address', $email, PDO::PARAM_STR);

然后调用另一个bindParam,如

$prepSelectUser->bindParam(':password', $password, PDO::PARAM_STR);