<legend id='46TKM'><style id='46TKM'><dir id='46TKM'><q id='46TKM'></q></dir></style></legend>

    <i id='46TKM'><tr id='46TKM'><dt id='46TKM'><q id='46TKM'><span id='46TKM'><b id='46TKM'><form id='46TKM'><ins id='46TKM'></ins><ul id='46TKM'></ul><sub id='46TKM'></sub></form><legend id='46TKM'></legend><bdo id='46TKM'><pre id='46TKM'><center id='46TKM'></center></pre></bdo></b><th id='46TKM'></th></span></q></dt></tr></i><div id='46TKM'><tfoot id='46TKM'></tfoot><dl id='46TKM'><fieldset id='46TKM'></fieldset></dl></div>

        <bdo id='46TKM'></bdo><ul id='46TKM'></ul>
      <tfoot id='46TKM'></tfoot>

    1. <small id='46TKM'></small><noframes id='46TKM'>

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

      时间:2023-07-31
    2. <tfoot id='58EI9'></tfoot>
        <tbody id='58EI9'></tbody>
        <legend id='58EI9'><style id='58EI9'><dir id='58EI9'><q id='58EI9'></q></dir></style></legend>

        <i id='58EI9'><tr id='58EI9'><dt id='58EI9'><q id='58EI9'><span id='58EI9'><b id='58EI9'><form id='58EI9'><ins id='58EI9'></ins><ul id='58EI9'></ul><sub id='58EI9'></sub></form><legend id='58EI9'></legend><bdo id='58EI9'><pre id='58EI9'><center id='58EI9'></center></pre></bdo></b><th id='58EI9'></th></span></q></dt></tr></i><div id='58EI9'><tfoot id='58EI9'></tfoot><dl id='58EI9'><fieldset id='58EI9'></fieldset></dl></div>
            <bdo id='58EI9'></bdo><ul id='58EI9'></ul>

                <small id='58EI9'></small><noframes id='58EI9'>

                本文介绍了在准备好的语句中使用通配符 - MySQLi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

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

                I'm trying to run the following query, and I'm having trouble with the wildcard.

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

                我收到一条错误消息:无法通过引用传递参数 2.我需要使用通配符的原因是该列的数据包含序列化数组.我想,如果有更简单的方法来处理这个问题,我能做什么?

                I'm getting an error that states: Cannot pass parameter 2 by reference. The reason I need to use the wildcard is because the column's data contains serialized arrays. I guess, if there's an easier way to handle this, what could I do?

                提前致谢!

                推荐答案

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

                You have to pass parameters to bind_param() by reference, which means you have to pass a single variable (not a concatenated string). There's no reason you can't construct such a variable specifically to pass in, though:

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

                这篇关于在准备好的语句中使用通配符 - MySQLi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli忽略表中的第一行 下一篇:mySQLi 准备好的语句无法 get_result()

                相关文章

                最新文章

              • <small id='PTNxO'></small><noframes id='PTNxO'>

              • <legend id='PTNxO'><style id='PTNxO'><dir id='PTNxO'><q id='PTNxO'></q></dir></style></legend>
                    <bdo id='PTNxO'></bdo><ul id='PTNxO'></ul>
                1. <tfoot id='PTNxO'></tfoot>

                    <i id='PTNxO'><tr id='PTNxO'><dt id='PTNxO'><q id='PTNxO'><span id='PTNxO'><b id='PTNxO'><form id='PTNxO'><ins id='PTNxO'></ins><ul id='PTNxO'></ul><sub id='PTNxO'></sub></form><legend id='PTNxO'></legend><bdo id='PTNxO'><pre id='PTNxO'><center id='PTNxO'></center></pre></bdo></b><th id='PTNxO'></th></span></q></dt></tr></i><div id='PTNxO'><tfoot id='PTNxO'></tfoot><dl id='PTNxO'><fieldset id='PTNxO'></fieldset></dl></div>