您是否知道任何可以为 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已被弃用-它只是费力代码的一个例子)