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

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

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

        <bdo id='WbAxs'></bdo><ul id='WbAxs'></ul>
      <tfoot id='WbAxs'></tfoot>

      PHP PDO bindParam 陷入了 foreach

      时间:2023-09-20

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

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

          <tfoot id='XYfFZ'></tfoot>
          • <legend id='XYfFZ'><style id='XYfFZ'><dir id='XYfFZ'><q id='XYfFZ'></q></dir></style></legend>
              <tbody id='XYfFZ'></tbody>

              1. 本文介绍了PHP PDO bindParam 陷入了 foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个这样的循环:

                foreach($Fields as $Name => $Value){$Query->bindParam(':'.$Name, $Value, PDO::PARAM_STR);}

                没什么复杂的.但是,每个值都设置为数组中的最后一个 ($Fields).

                我该如何解决?

                解决方案

                然而,感谢这个 伙计们.我发现您需要在之前使用 & 通过引用传递值:

                foreach($Fields as $Name => &$Value){$Query->bindParam(':'.$Name, $Value, PDO::PARAM_STR);}

                这让我发疯了.

                来自 PHP.net 的实际报价:

                <块引用>

                Vili 2010 年 5 月 28 日 12:01

                这有效(参考 $val):

                 &$val){$sth->bindParam($key, $val);}?>

                <块引用>

                这会失败($val by value,因为bindParam需要&$variable):

                 $val) {$sth->bindParam($key, $val);}?>

                I had a loop like that :

                foreach($Fields as $Name => $Value){
                    $Query->bindParam(':'.$Name, $Value, PDO::PARAM_STR);
                }
                

                Nothing complicated. However, each value was set to the last one in the array ($Fields).

                How can I fix that ?

                解决方案

                However, thanks to this guys. I found out that you need to pass the value by reference with a & before like that :

                foreach($Fields as $Name => &$Value){
                    $Query->bindParam(':'.$Name, $Value, PDO::PARAM_STR);
                }
                

                This was driving me nuts.

                Actual quote from PHP.net :

                Vili 28-May-2010 12:01

                This works ($val by reference):

                <?php
                foreach ($params as $key => &$val){
                    $sth->bindParam($key, $val);
                }
                ?>
                

                This will fail ($val by value, because bindParam needs &$variable):

                <?php
                foreach ($params as $key => $val) {
                    $sth->bindParam($key, $val);
                }
                ?>
                

                这篇关于PHP PDO bindParam 陷入了 foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:PDO::exec() 还是 PDO::query()? 下一篇:如何在 PHP 中选择要与 PDO 一起使用的 MySQL 数据库

                相关文章

                最新文章

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

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

                    <tfoot id='VqqXW'></tfoot>