如何将多个参数结合到库MySQLi查询[关闭](how to bind multiple param

2019-09-04 02:28发布

我有一个MySQL查询,但我不能把它绑定PARAM

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():在类型定义字符串元素数不匹配绑定变量的数

Answer 1:

这是在结合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
}


Answer 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();


文章来源: how to bind multiple parameters to MySQLi query [closed]
标签: php mysqli