1

您是否知道任何可以为 MySQL Db 执行一些基本验证和转义功能的开源库或框架。

我的设想是:

//give it something to perform the quote() quoteInto() methods
$lib->setSanitizor($MyZend_DBAdaptor); 

//tell it structure of the table - colnames/coltypes/ etc
$lib->setTableDescription($tableDescArray); 

//use it to validate and escape according to coltype 
foreach ($prospectiveData as $colName => $rawValue)
if ( $lib->isValid($colName, $rawValue))
 {
 //add it to the set clause
 $setValuesArray[$lib->escapeIdentifier($colName)] = $lib->getEscapedValue($colName,$rawValue);
 }
else {
 throw new Exception($lib->getErrorMessage());
 }

ETC...

我研究过 - Zend_Db_Table (知道表的描述)和 - Zend_Db_Adaptor (知道如何根据 TYPE 转义/清理值)

但是尽管它们可以清理,但它们不会在更新/插入之前自动执行任何巧妙的验证工作

任何人都知道一个好的 PHP 库来执行这种我可以使用而不是自己编写的验证吗?

我设想了很多这样的东西:

   ...  
   elseif (eregi('^INT|^INTEGER',$dataset_element_arr[col_type]))
    {
    $datatype='int';

    if (eregi('unsigned',$dataset_element_arr[col_type]))
        {
        $int_max_val=4294967296;
        $int_min_val=0;
        }
    else    {
        $int_max_val=2147483647;
        $int_min_val=-2147483648;
        }
    }

(ps我知道eregi已被弃用-它只是费力代码的一个例子)

4

1 回答 1

1

我在 Zend_Db 中编写了很多代码。

该代码不会在更新/插入中进行大量清理或转义,因为它使用查询参数。如果使用参数将动态值传递给查询,则无需担心 SQL 注入。

有关更多详细信息,请参阅我对避免使用 Zend_Db 类进行 MySQL 注入的回答。

MySQL 还支持一些比 PHP 整数更大的数据类型BIGINT,所以你必须用 PHP 字符串来表示它们。然后是 MySQLDATE值等等。最好通过将值插入数据库并处理任何异常来验证这些值。

于 2010-04-23T02:02:41.403 回答