<legend id='NWWKB'><style id='NWWKB'><dir id='NWWKB'><q id='NWWKB'></q></dir></style></legend>

    • <bdo id='NWWKB'></bdo><ul id='NWWKB'></ul>

      1. <tfoot id='NWWKB'></tfoot>

        <small id='NWWKB'></small><noframes id='NWWKB'>

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

        PDO::bindParam 在 foreach 循环中,所有值都设置为相

        时间:2023-09-23
          <bdo id='v8TDc'></bdo><ul id='v8TDc'></ul>
        • <legend id='v8TDc'><style id='v8TDc'><dir id='v8TDc'><q id='v8TDc'></q></dir></style></legend>
            <tbody id='v8TDc'></tbody>
          <tfoot id='v8TDc'></tfoot>

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

              <small id='v8TDc'></small><noframes id='v8TDc'>

                • 本文介绍了PDO::bindParam 在 foreach 循环中,所有值都设置为相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 a 函数让重复的数据库调用变得更容易一些,该函数应该(理论上)允许我使用数组绑定参数:

                  I am trying to make life a little bit easier for repeated database calls with the a function which should (in theory) allow me to bind parameters using an array:

                      function query($tblName,$queryParams = false){
                      $this->queryObject = $this->con->prepare($this->queryString);
                      if($queryParams){
                          foreach ($queryParams as $key => $value) {
                              $this->queryObject->bindParam($key, $value);
                          }
                      }
                      $this->queryResult = $this->queryObject->execute();
                      print_r($this->queryResult);
                  }
                  

                  然后我会这样称呼它:

                  $queryParams = array(':userName' => $_POST['username'], ':password' => $_POST['password'], ':salt'=>$userUser->salt, ':userEmail'=>$_POST['email']);
                  $registrationDb->query('tblUser', $queryParams);
                  

                  数据库连接正在工作,正在写入,但是,所有值都被设置为 $_POST['email],我无法弄清楚为什么会这样正在发生.

                  The database connection is working, and there is a write being made, however, all the values are being set to $_POST['email], and I can't puzzle out why this is happening.

                  有没有更好的方法来做到这一点?

                  Is there a better way to be doing this?

                  推荐答案

                  bindParam 通过引用绑定变量,所以你需要 bindValue 代替:

                  bindParam binds variable by reference, so you need bindValue instead:

                  $this->queryObject->bindValue($key, $value);
                  

                  这篇关于PDO::bindParam 在 foreach 循环中,所有值都设置为相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何通过 foreach 循环修改数组的值? 下一篇:计算 foreach 循环中的迭代次数

                  相关文章

                  最新文章

                  <small id='xmZcc'></small><noframes id='xmZcc'>

                  1. <legend id='xmZcc'><style id='xmZcc'><dir id='xmZcc'><q id='xmZcc'></q></dir></style></legend>

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

                        <bdo id='xmZcc'></bdo><ul id='xmZcc'></ul>
                    1. <tfoot id='xmZcc'></tfoot>