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

    1. <small id='8csI2'></small><noframes id='8csI2'>

      <legend id='8csI2'><style id='8csI2'><dir id='8csI2'><q id='8csI2'></q></dir></style></legend>

      将参数与参数数组绑定

      时间:2023-07-31
      <legend id='KdTi1'><style id='KdTi1'><dir id='KdTi1'><q id='KdTi1'></q></dir></style></legend>
      • <small id='KdTi1'></small><noframes id='KdTi1'>

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

              <tbody id='KdTi1'></tbody>

                <bdo id='KdTi1'></bdo><ul id='KdTi1'></ul>

              • 本文介绍了将参数与参数数组绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个函数可以做到这一点:

                I have a function that does this:

                function registerUser($firstName, $lastName, $address, $postcode, $email, $password)
                {
                    $params = array($firstName, $lastName, $address, $postcode, $email, $password);
                    $result = $this->db->bind("INSERT INTO Users VALUES (?, ?, ?, ?, ?, ?)", 'ssssss', $params);
                }
                

                发送到我的数据库类,它执行以下操作:

                Which sends off to my database class, which does this:

                public function bind($query, $type, $params)
                {
                    $this->query = $query;
                    $stmt = $this->mysqli->prepare($this->query);
                    $stmt->bind_param($type, $param);
                    $stmt->execute;
                }
                

                问题是这行不通.

                我希望做的是获取 $params 列表并让它在 $type 之后列出它们,这样查询将类似于:

                What I was hoping to do, was to take the $params list and have it list them after the $type, so that the query would resemble:

                $stmt->bind_param('ssssss', $firstName, $lastName, $address, $postcode, $email, $password);
                

                但显然我的做法是错误的.

                But obviously I'm going about it the wrong way.

                有没有办法让数组...转换成一个列表,以便在 bind_param 查询阶段打印出来?

                is there a way to make the array...transform as it were, into a list to be printed out at the bind_param query stage?

                推荐答案

                call_user_func_array使用参数数组调用回调"

                call_user_func_array "Call a callback with an array of parameters"

                call_user_func_array(array($stmt, "bind_param"), array_merge(array($type), $params));
                

                应该做的工作

                UPDATE:您还必须更改您的 params 数组:

                UPDATE: you have also to change your params array:

                $params = array(&$firstName, &$lastName, &$address, &$postcode, &$email, &$password);
                

                as mysqli_stmt::bind_param 期待第二个和以下参数的引用.

                as mysqli_stmt::bind_param expects the second and the following parameters by reference.

                您的查询似乎是错误的.也许你的字段比变量少.做:

                Your query seems to be wrong. Maybe you have less fields than you have variables there. Do:

                "INSERT INTO Users (field1, field2, field3, field4, field5, field6) VALUES (?, ?, ?, ?, ?, ?)"
                

                用正确的名称替换字段的名称

                where you replace the name of the fields by the correct names

                这篇关于将参数与参数数组绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:MySQLi 中的 SELECT * FROM 下一篇:如何回显 MySQLi 准备好的语句?

                相关文章

                最新文章

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

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

                    <tfoot id='SYEnY'></tfoot>