如何将多个参数绑定到MySQLi查询

AF.*_*F.P 23 php mysqli

我有一个mysql查询,但我不能绑定它的参数

SELECT users.email,users.handle,userprofile.mobile FROM users,userprofile WHERE users.email =? OR users.handle =? OR userprofile.mobile=?
Run Code Online (Sandbox Code Playgroud)

我试过下面的线

$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 '......';
    }
}
Run Code Online (Sandbox Code Playgroud)

但我收到并错误:

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

Fab*_*bio 30

这是绑定params的正确语法 mysqli

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

if ($stmt = $mysqli->prepare($SQL)) {

     $stmt->bind_param("sss", $one,$two,$three);
     $stmt->execute();

     //do stuff
}
Run Code Online (Sandbox Code Playgroud)

  • 只是提醒:参数可能是以下四种类型之一:i - 整数d - 双s - 字符串b - BLOB (3认同)
  • 如果我将它们作为数组接收,我可以调用 bind_params 3 次来绑定不同的参数吗? (2认同)
  • @KoenDemonie实际上没有什么区别但是如果你通过点击"2013年5月17日15:11编辑"查看问题历史,你会发现差异.Op使用bindParam而不是bind_param (2认同)

Jos*_*tis 5

尝试这个...

$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();
Run Code Online (Sandbox Code Playgroud)