27

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

4

2 回答 2

38

这是绑定参数的正确语法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
于 2013-05-17T15:12:13.523 回答
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();
于 2013-05-17T15:12:38.703 回答