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

    1. <tfoot id='SI7Rk'></tfoot>
    2. <small id='SI7Rk'></small><noframes id='SI7Rk'>

      <legend id='SI7Rk'><style id='SI7Rk'><dir id='SI7Rk'><q id='SI7Rk'></q></dir></style></legend>
    3. MySQLi 中的参数

      时间:2023-07-31
      <i id='qJ2Pt'><tr id='qJ2Pt'><dt id='qJ2Pt'><q id='qJ2Pt'><span id='qJ2Pt'><b id='qJ2Pt'><form id='qJ2Pt'><ins id='qJ2Pt'></ins><ul id='qJ2Pt'></ul><sub id='qJ2Pt'></sub></form><legend id='qJ2Pt'></legend><bdo id='qJ2Pt'><pre id='qJ2Pt'><center id='qJ2Pt'></center></pre></bdo></b><th id='qJ2Pt'></th></span></q></dt></tr></i><div id='qJ2Pt'><tfoot id='qJ2Pt'></tfoot><dl id='qJ2Pt'><fieldset id='qJ2Pt'></fieldset></dl></div>
      <tfoot id='qJ2Pt'></tfoot>
      • <bdo id='qJ2Pt'></bdo><ul id='qJ2Pt'></ul>
      • <legend id='qJ2Pt'><style id='qJ2Pt'><dir id='qJ2Pt'><q id='qJ2Pt'></q></dir></style></legend>
            <tbody id='qJ2Pt'></tbody>
          1. <small id='qJ2Pt'></small><noframes id='qJ2Pt'>

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

                问题描述

                我在 MySQLi 中使用 PHP,我遇到了类似查询的情况

                I'm using PHP with MySQLi, and I'm in a situation where I have queries like

                SELECT $fields FROM $table WHERE $this=$that AND $this2=$that2
                

                到目前为止,我已经编写了一些代码来拼接我给它的数组,例如:

                So far I've written some code that splices up an array that I give it, for example:

                $search = array(name=michael, age=20) //turns into
                SELECT $fields FROM $table WHERE name=michael AND age=20
                

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

                Is there a more efficient way to do this?

                我很担心 MySQL 注入 - 这似乎很容易受到攻击.谢谢!

                I'm rather worried about MySQL injections - this seems very vulnerable. Thanks!

                推荐答案

                奇怪的是,问题的标题基本上就是它的答案.你想要做这样的事情,使用 mysqli 参数化查询:

                Oddly enough, the title to your question is basically the answer to it. You want to do something like this, using mysqli parameterized queries:

                $db = new mysqli(<database connection info here>);
                $name = "michael";
                $age = 20;
                
                $stmt = $db->prepare("SELECT $fields FROm $table WHERE name = ? AND age = ?");
                $stmt->bind_param("si", $name, $age);
                $stmt->execute();
                $stmt->close();
                

                更多信息在mysqli部分,特别是相关的功能MySQLi_STMT.

                More information in the mysqli section of the manual, specifically the functions related to MySQLi_STMT.

                请注意,我个人更喜欢使用 PDO 而不是 mysqli,我不就像 mysqli 所做的所有 bind_param/bind_result 东西一样.如果我必须使用它,我会围绕它编写一个包装器,使其更像 PDO.

                Note that I personally prefer using PDO over mysqli, I don't like all the bind_param / bind_result stuff that mysqli does. If I have to use it I write a wrapper around it to make it work more like PDO.

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

                上一篇:mysqli_fetch_array while 循环列 下一篇:INSERT - 绑定变量的数量与准备好的语句中的字段

                相关文章

                最新文章

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

                  2. <legend id='Pgs7D'><style id='Pgs7D'><dir id='Pgs7D'><q id='Pgs7D'></q></dir></style></legend>

                      <bdo id='Pgs7D'></bdo><ul id='Pgs7D'></ul>
                  3. <small id='Pgs7D'></small><noframes id='Pgs7D'>