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

          <bdo id='JIqsp'></bdo><ul id='JIqsp'></ul>
        <legend id='JIqsp'><style id='JIqsp'><dir id='JIqsp'><q id='JIqsp'></q></dir></style></legend>
      2. 编写 PHP SQL 更新语句的最佳方法

        时间:2024-08-22

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

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

                  <tbody id='kc1zr'></tbody>
              • <i id='kc1zr'><tr id='kc1zr'><dt id='kc1zr'><q id='kc1zr'><span id='kc1zr'><b id='kc1zr'><form id='kc1zr'><ins id='kc1zr'></ins><ul id='kc1zr'></ul><sub id='kc1zr'></sub></form><legend id='kc1zr'></legend><bdo id='kc1zr'><pre id='kc1zr'><center id='kc1zr'></center></pre></bdo></b><th id='kc1zr'></th></span></q></dt></tr></i><div id='kc1zr'><tfoot id='kc1zr'></tfoot><dl id='kc1zr'><fieldset id='kc1zr'></fieldset></dl></div>
                  <bdo id='kc1zr'></bdo><ul id='kc1zr'></ul>
                  <tfoot id='kc1zr'></tfoot>
                  本文介绍了编写 PHP SQL 更新语句的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个 PHP SQL 语句:

                  I have this PHP SQL statement:

                  $updateCategory = "UPDATE category 
                                     SET name=".$name.", description=".$description.",
                                         parent=".$parent.", active=".$active." 
                                     WHERE id=".$catID."";
                  

                  最好的写法是什么?

                  谢谢,

                  克里斯.

                  推荐答案

                  我建议你使用prepared statements而不是将查询字符串连接在一起:

                  I suggest you use prepared statements instead of concatenating the query string together:

                  $sql = 'UPDATE 
                             category
                          SET
                             name=:name,
                             description=:description,
                             parent=:parent, 
                             active=:active
                          WHERE
                             id=:catID';
                  

                  如果您使用的是 PDO,我强烈建议您这样做:p>

                  if you are using PDO, which I strongly suggest, you would then call it like this:

                  $params = array(
                      ':name'        => $name,
                      ':description' => $description,
                      ':parent'      => $parent,
                      ':active'      => $active,
                      ':catID'       => $catID
                  );
                  
                  $stmt = $pdo->prepare($sql);
                  $stmt->execute($params);
                  

                  您可能会问,为什么要这么麻烦?"这种方法的优势非常明显:

                  You might ask, "why all this hassle?" The advantages of this approach are quite overwhelming:

                  • 您不必关心 SQL 注入,因为数据库驱动程序现在可以处理输入参数的正确转换
                  • 您不必关心转义特殊字符,但您可以专注于您想要实现的目标,而不是如何实现它:-)

                  这篇关于编写 PHP SQL 更新语句的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带连接的 Codeigniter 活动记录更新 下一篇:PHP->PDO 更新声明

                  相关文章

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

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

                    • <bdo id='O8qEK'></bdo><ul id='O8qEK'></ul>
                  1. <small id='O8qEK'></small><noframes id='O8qEK'>