我有一个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():类型定义字符串中的元素数与绑定变量数不匹配
我有一个代码来检查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", $email,$username,$mobile);
$stmt->execute();
if($stmt->num_rows){
$result = $stmt->get_result();
$row = $result->fetch_array(MYSQLI_NUM);
if($row[0] ==$email){echo 'email exist';}
if($row[1] ==$username){echo 'username exist';}
if($row[2] ==$mobile){echo 'mobile exist';}
}
else{
echo 'OK';
}
Run Code Online (Sandbox Code Playgroud)
如果在用户数据已存在时有效.但如果用户数据不存在,则else不起作用!为什么?