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

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

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

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

        使用 Zend_Db 类避免 MySQL 注入

        时间:2023-05-31
      1. <i id='JOs3G'><tr id='JOs3G'><dt id='JOs3G'><q id='JOs3G'><span id='JOs3G'><b id='JOs3G'><form id='JOs3G'><ins id='JOs3G'></ins><ul id='JOs3G'></ul><sub id='JOs3G'></sub></form><legend id='JOs3G'></legend><bdo id='JOs3G'><pre id='JOs3G'><center id='JOs3G'></center></pre></bdo></b><th id='JOs3G'></th></span></q></dt></tr></i><div id='JOs3G'><tfoot id='JOs3G'></tfoot><dl id='JOs3G'><fieldset id='JOs3G'></fieldset></dl></div>
        <tfoot id='JOs3G'></tfoot>

            <legend id='JOs3G'><style id='JOs3G'><dir id='JOs3G'><q id='JOs3G'></q></dir></style></legend>
            • <bdo id='JOs3G'></bdo><ul id='JOs3G'></ul>

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

                <tbody id='JOs3G'></tbody>
                  本文介绍了使用 Zend_Db 类避免 MySQL 注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前使用 Zend_Db 来管理我的查询.我已经编写了可以执行如下查询的代码:

                  I currently use Zend_Db to manage my queries. I've written already code that preforms queries like the one below:

                  $handle->select()->from('user_id')
                                     ->where('first_name=?', $id)
                                     ->where('last_name=?', $lname)
                  

                  假设 Zend_Db 会,我在没有清理输入的情况下完成了这项工作.Zend 会这样做吗?

                  I've done this without sanitizing the input, assuming Zend_Db will. Does Zend do this?

                  另一个问题:Zend_Db 是否清理 insert('table', $data)update 查询?

                  Another question: Does Zend_Db sanitize insert('table', $data) and update queries?

                  谢谢.

                  推荐答案

                  当我担任该项目的团队负责人(直到 1.0 版)时,我在 Zend Framework 中编写了大量用于数据库参数和引用的代码.

                  I wrote a lot of the code for database parameters and quoting in Zend Framework while I was the team lead for the project (up to version 1.0).

                  我尽可能鼓励最佳实践,但我必须在易用性和易用性之间取得平衡.

                  I tried to encourage best practices where possible, but I had to strike a balance with ease of use.

                  请注意,您始终可以检查 Zend_Db_Select 对象的字符串值,以查看它如何决定进行引用.

                  Note that you can always examine the string value of a Zend_Db_Select object, to see how it has decided to do quoting.

                  print $select; // invokes __toString() method
                  

                  您也可以使用 Zend_Db_Profiler 检查由 Zend_Db 代表您运行的 SQL.

                  Also you can use the Zend_Db_Profiler to inspect the SQL that is run on your behalf by Zend_Db.

                  $db->getProfiler()->setEnabled(true);
                  $db->update( ... );
                  print $db->getProfiler()->getLastQueryProfile()->getQuery(); 
                  print_r $db->getProfiler()->getLastQueryProfile()->getQueryParams(); 
                  $db->getProfiler()->setEnabled(false);
                  

                  以下是您的具体问题的一些答案:

                  Here are some answers to your specific questions:

                  • Zend_Db_Select::where('last_name=?', $lname)

                  值被适当引用.虽然?"看起来像一个参数占位符,但在这个方法中,参数实际上被适当地引用和插入.所以它不是一个真正的查询参数.实际上,以下两条语句产生的查询与上述用法完全相同:

                  Values are quoted appropriately. Although the "?" looks like a parameter placeholder, in this method the argument is actually quoted appropriately and interpolated. So it's not a true query parameter. In fact, the following two statements produce exactly the same query as the above usage:

                  $select->where( $db->quoteInto('last_name=?', $lname) );
                  $select->where( 'last_name=' . $db->quote($lname) );
                  

                  然而,如果您传递的参数是 Zend_Db_Expr 类型的对象,则它不会被引用.您应对 SQL 注入风险负责,因为它是逐字插入的,以支持表达式值:

                  However, if you pass a parameter that is an object of type Zend_Db_Expr, then it's not quoted. You're responsible for SQL injection risks, because it's interpolated verbatim, to support expression values:

                  $select->where('last_modified < ?', new Zend_Db_Expr('NOW()'))
                  

                  该表达式的任何其他需要引用或分隔的部分是您的责任.例如,如果您将任何 PHP 变量插入到表达式中,安全是您的责任.如果您的列名是 SQL 关键字,您需要自己用 quoteIdentifier() 分隔它们.示例:

                  Any other part of that expression that needs to be quoted or delimited is your responsibility. E.g., if you interpolate any PHP variables into the expression, safety is your responsibility. If you have column names that are SQL keywords, you need to delimit them yourself with quoteIdentifier(). Example:

                  $select->where($db->quoteIdentifier('order').'=?', $myVariable)
                  

                • Zend_Db_Adapter_Abstract::insert( array('colname' => 'value') )

                  表名和列名是分隔的,除非你关闭AUTO_QUOTE_IDENTIFIERS.

                  Table name and column names are delimited, unless you turn off AUTO_QUOTE_IDENTIFIERS.

                  值被参数化为真正的查询参数(未插入).除非值是一个 Zend_Db_Expr 对象,在这种情况下它是逐字插入的,所以你可以插入表达式或 NULL 或其他什么.

                  Values are parameterized as true query parameters (not interpolated). Unless the value is a Zend_Db_Expr object, in which case it's interpolated verbatim, so you can insert expressions or NULL or whatever.

                  Zend_Db_Adapter_Abstract::update( array('colname' => 'value'), $where )

                  表名和列名是分隔的,除非你关闭AUTO_QUOTE_IDENTIFIERS.

                  Table name and column names are delimited, unless you turn off AUTO_QUOTE_IDENTIFIERS.

                  值是参数化的,除非它们是 Zend_Db_Expr 对象,如 insert() 方法.

                  Values are parameterized, unless they are Zend_Db_Expr objects, as in insert() method.

                  $where 参数根本没有被过滤,因此您应对该参数中的任何 SQL 注入风险负责.您可以使用 quoteInto() 方法来帮助更方便地引用.

                  The $where argument is not filtered at all, so you're responsible for any SQL injection risks in that one. You can make use of the quoteInto() method to help make quoting more convenient.

                  这篇关于使用 Zend_Db 类避免 MySQL 注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                • 上一篇:Zend框架中重定向和转发有什么区别 下一篇:Zend_Form - 基于数组的元素?

                  相关文章

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

                • <legend id='oaMwD'><style id='oaMwD'><dir id='oaMwD'><q id='oaMwD'></q></dir></style></legend>

                    <tfoot id='oaMwD'></tfoot>

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