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

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

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

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

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

      如何回显 MySQLi 准备好的语句?

      时间:2023-07-31

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

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

              <tbody id='oAAzO'></tbody>
            <legend id='oAAzO'><style id='oAAzO'><dir id='oAAzO'><q id='oAAzO'></q></dir></style></legend>
          1. <tfoot id='oAAzO'></tfoot>
              <bdo id='oAAzO'></bdo><ul id='oAAzO'></ul>
                本文介绍了如何回显 MySQLi 准备好的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我目前正在使用 MySQLi,试图弄清楚它是如何工作的.在我目前的项目中,我总是喜欢在编码时回显查询字符串,以确保一切正确,并快速调试我的代码.但是……我如何使用准备好的 MySQLi 语句来做到这一点?

                I'm playing around with MySQLi at the moment, trying to figure out how it all works. In my current projects I always like to echo out a query string while coding, just to make sure that everything is correct, and to quickly debug my code. But... how can I do this with a prepared MySQLi statement?

                示例:

                $id = 1;
                $baz = 'something';
                
                if ($stmt = $mysqli->prepare("SELECT foo FROM bar WHERE id=? AND baz=?")) {
                  $stmt->bind_param('is',$id,$baz);
                  // how to preview this prepared query before acutally executing it?
                  // $stmt->execute();
                }

                我一直在浏览这个列表(http://www.php.net/mysqli) 但没有任何运气.

                I've been going through this list (http://www.php.net/mysqli) but without any luck.


                编辑

                好吧,如果在 MySQLi 中不可能,也许我会坚持这样的:

                Well, if it's not possible from within MySQLi, maybe I'll stick with something like this:

                function preparedQuery($sql,$params) {
                  for ($i=0; $i<count($params); $i++) {
                    $sql = preg_replace('/?/',$params[$i],$sql,1);
                  }
                  return $sql;
                }
                
                $id = 1;
                $baz = 'something';
                
                $sql = "SELECT foo FROM bar WHERE id=? AND baz=?";
                
                echo preparedQuery($sql,array($id,$baz));
                
                // outputs: SELECT foo FROM bar WHERE id=1 AND baz=something
                

                显然远非完美,因为它仍然相当多余—我想阻止的事情—它也没有让我知道 MySQLi 对数据做了什么.但是我想通过这种方式我可以快速查看所有数据是否都存在并且位于正确的位置,并且与手动将变量拟合到查询中相比,它可以为我节省一些时间—对于许多变量,这可能会很痛苦.

                Far from perfect obviously, since it's still pretty redundant — something I wanted to prevent — and it also doesn't give me an idea as to what's being done with the data by MySQLi. But I guess this way I can quickly see if all the data is present and in the right place, and it'll save me some time compared to fitting in the variables manually into the query — that can be a pain with many vars.

                推荐答案

                我认为你不能——至少不是你希望的那样.您要么必须自己构建查询字符串并执行它(即不使用语句),要么寻找或创建支持该功能的包装器.我使用的是 Zend_Db,这就是我要做的:

                I don't think you can - at least not in the way that you were hoping for. You would either have to build the query string yourself and execute it (ie without using a statement), or seek out or create a wrapper that supports that functionality. The one I use is Zend_Db, and this is how I would do it:

                $id = 5;
                $baz = 'shazam';
                $select = $db->select()->from('bar','foo')
                                       ->where('id = ?', $id)
                                       ->where('baz = ?', $baz); // Zend_Db_Select will properly quote stuff for you
                print_r($select->__toString()); // prints SELECT `bar`.`foo` FROM `bar` WHERE (id = 5) AND (baz = 'shazam')
                

                这篇关于如何回显 MySQLi 准备好的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:将参数与参数数组绑定 下一篇:带有动态参数的动态选择 mysqli 查询返回错误与绑

                相关文章

                最新文章

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

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

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

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

                  <tfoot id='l0MB2'></tfoot>