如何将多个参数绑定到 MySQLi 查询 [已关闭]

2022-08-30 16:05:42

我有一个mysql查询,但我无法绑定它的参数

SELECT users.email,users.handle,userprofile.mobile FROM users,userprofile WHERE users.email =? OR users.handle =? OR userprofile.mobile=?

我试过下面行

$query = "SELECT users.email,users.handle,userprofile.mobile FROM users,userprofile WHERE users.email =? OR users.handle =? OR userprofile.mobile=?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("sss",$email,$username,$mobile);
if ($stmt->execute()) {
if($stmt->num_rows){
   echo '......';
    }
}

但我收到并出错:

警告:mysqli_stmt::bind_param(): 类型定义字符串中的元素数与绑定变量数不匹配


答案 1

这是 中绑定参数的正确语法mysqli

$SQL = "SELECT 
              users.email,
              users.handle,
              userprofile.mobile 
        FROM users,userprofile      
        WHERE users.email =? OR users.handle =? OR userprofile.mobile=?";

$stmt = $mysqli->prepare($SQL);
   
$stmt->bind_param("sss", $one,$two,$three);
$stmt->execute();

//do stuff

答案 2

试试这个...

$stmt = $dbConn->prepare("SELECT users.email,users.handle,userprofile.mobile FROM users,userprofile WHERE users.email = ? OR users.handle = ? OR userprofile.mobile= ?");
$stmt->bind_param("sss", $email, $handle, $mobile);
$stmt->execute();

推荐