rah*_*ari 7 php quote zend-framework2
在Zend Framework 1中,有一个数据库适配器的quoteinto方法,可用于引用sql语句.
我想知道它在Zend Framework 2中的等价物吗?
不幸的是,通过在ZF 2.0中quoteInto()
引入新方法,删除了该方法Zend\Db
.并且没有相同的行为具有完全相同的行为.
在ZF2中有quoteValue()
方法.此方法将一个值作为参数,然后引用该值,以便您可以安全地将其作为值放入SQL查询中.
但是,您可以使用quoteValue()
复制ZF1 quoteInto()
方法的行为.你可以简单地采取的代码quoteInto()
从方法ZF1,并应用quoteValue()
在ZF2平台对象将其方法:
// modified quoteInto() function for ZF2
function quoteInto($text, $value, $platform, $count = null)
{
if ($count === null) {
return str_replace('?', $platform->quoteValue($value), $text);
} else {
while ($count > 0) {
if (strpos($text, '?') !== false) {
$text = substr_replace($text, $platform->quoteValue($value), strpos($text, '?'), 1);
}
--$count;
}
return $text;
}
}
Run Code Online (Sandbox Code Playgroud)
有一些差异.ZF1有一个$type
参数,但是由于ZF2使用这些东西的方式,类型参数没有多大意义.并且有一个$platform
参数,因为此方法依赖于该quoteValue()
方法的平台.
归档时间: |
|
查看次数: |
2339 次 |
最近记录: |