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

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

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

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

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

      带有准备好的语句的 PDO bindParam() 不起作用

      时间:2023-10-04
        <bdo id='BjJw6'></bdo><ul id='BjJw6'></ul>

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

              1. <small id='BjJw6'></small><noframes id='BjJw6'>

                <legend id='BjJw6'><style id='BjJw6'><dir id='BjJw6'><q id='BjJw6'></q></dir></style></legend>
              2. 本文介绍了带有准备好的语句的 PDO bindParam() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                好的,这就是问题所在:

                这有效:

                $STH = $DBH->prepare("SELECT * FROM juegos WHERE id = 1");$STH->execute();

                这不会:

                $STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");$STH->bindParam(':id', '1', PDO::PARAM_STR);$STH->execute();

                我到底做错了什么?它甚至不抛出异常

                谢谢大家!

                另外,这是完整的代码

                setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );$STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");$STH->bindParam(':id', '1', PDO::PARAM_STR);$STH->execute();$STH->setFetchMode(PDO::FETCH_ASSOC);while($row = $STH->fetch()) {echo $row['nombre']."<br/>";}$DBH = 空;echo "Todo salió bien";} catch (PDOException $e) {echo "错误";}?>

                解决方案

                使用 bindParam() 变量是 绑定为引用.

                字符串不能通过引用传递.>

                可以通过引用传递以下内容:

                <块引用>

                变量,即 foo($a)

                新语句,即 foo(new foobar())

                从函数返回的引用

                尝试使用 bindValue()

                $STH->bindValue(':id', '1', PDO::PARAM_STR);

                Ok, this is the problem:

                This works:

                $STH = $DBH->prepare("SELECT * FROM juegos WHERE id = 1");
                $STH->execute();
                

                This doesn't:

                $STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");
                $STH->bindParam(':id', '1', PDO::PARAM_STR);
                $STH->execute();
                

                What in the world am I doing wrong? It doesn't even throw an exception

                Thank you everyone!

                Also, this is the whole code

                <?php
                    try {
                        $DBH = new PDO("everything is", "ok", "here");
                
                        $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
                
                        $STH = $DBH->prepare("SELECT * FROM juegos WHERE id = :id");
                        $STH->bindParam(':id', '1', PDO::PARAM_STR);
                        $STH->execute();
                
                        $STH->setFetchMode(PDO::FETCH_ASSOC);
                
                        while($row = $STH->fetch()) {
                            echo $row['nombre']."<br/>";
                        }
                
                        $DBH = null;
                
                        echo "Todo salió bien";
                
                    } catch (PDOException $e) {
                        echo "Error";
                    }
                
                ?>
                

                解决方案

                Using bindParam() the variable is bound as a reference.

                A string can't be passed by reference.

                The following things can be passed by reference:

                Variables, i.e. foo($a)

                New statements, i.e. foo(new foobar())

                References returned from functions

                Try using bindValue()

                $STH->bindValue(':id', '1', PDO::PARAM_STR);
                

                这篇关于带有准备好的语句的 PDO bindParam() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:带有 html 内容的 PHP PDO bindParam 下一篇:使用插入 PDO MySQL 获取插入 ID

                相关文章

                最新文章

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

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

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

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

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