gpt4 book ai didi

php - 在准备好的语句中使用通配符

转载 作者:可可西里 更新时间:2023-10-31 22:19:11 24 4
gpt4 key购买 nike

我正在尝试运行以下查询,但在使用通配符时遇到了问题。

function getStudents() {
global $db;
$users = array();
$query = $db->prepare("SELECT id, adminRights FROM users WHERE classes LIKE ? && adminRights='student'");
$query->bind_param('s', '%' . $this->className . '%');
$query->execute();
$query->bind_result($uid, $adminRights);
while ($query->fetch()) {
if (isset($adminRights[$this->className]) && $adminRights[$this->className] == 'student')
$users[] = $uid;
}
$query->close();
return $users;
}

我收到一条错误消息:

Cannot pass parameter 2 by reference.

我需要使用通配符的原因是列的数据包含序列化数组。我想,如果有更简单的方法来处理这个问题,我该怎么办?

最佳答案

您必须通过引用将参数传递给 bind_param(),这意味着您必须传递一个单个变量(而不是一个串联的字符串)。不过,您没有理由不能专门构造这样一个变量来传入:

$className = '%' . $this->className . '%';
$query->bind_param('s', $className);

关于php - 在准备好的语句中使用通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1352002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com