如何将多个参数绑定到MySQLi查询 [英] how to bind multiple parameters to MySQLi query

查看:55
本文介绍了如何将多个参数绑定到MySQLi查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a mysql query, but I can't bind param for it

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 '......';
    }
}

但是我已经收到并出现错误:

but I've received and error :

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

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables

推荐答案

这是绑定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
}

这篇关于如何将多个参数绑定到MySQLi查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆