Php 如何将多个参数绑定到MySQLi查询
我有一个mysql查询,但是我不能为它绑定paramPhp 如何将多个参数绑定到MySQLi查询,php,mysqli,Php,Mysqli,我有一个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,userp
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():类型中的元素数
定义字符串与绑定变量的数量不匹配
这是在
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
试试这个
$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();
您能否发布完整的查询代码,包括完整的prepare而不仅仅是sql语句当您在示例“sss”中传递多个参数时,实际上只是使用bindParam its actual$stmt->bind_param()重新发布了您的查询代码这意味着他想要绑定的3个变量都是字符串,他同时传递了所有3个变量,所以他需要使用bind_param而不是bindparam。如果他要像下面的例子那样单独绑定每个输入,他应该只在没有uu的情况下使用它。我编辑了我的帖子来解释更多的代码你实际上是在用OO方法打开mysqli,不是吗代码>不是以过程的方式进行的,在这种情况下,您必须传入链接id Too如果我以数组的形式接收到不同的参数,我可以调用bind_params 3次以绑定它们吗?只是提醒一下:参数可能是四种类型之一:I-整数d-双s-字符串b-blob此解决方案和代码之间的区别是什么提供?@KoenDemonie实际上没有区别,但如果你点击“5月17日13日15:11编辑”查看问题历史记录,你会发现区别。Op使用的是bindParam而不是bind_param