adodb中qstr的妙处
2009-08-24 By im502 评论关闭 365 views
使用adodb库的好处就在于里面会有很多好用的函数,今天说的就是qstr的用法,此函数会再提交到数据库之前将字符串里的引号转义,并用引号来包裹,比用addslashes要方便很多。
function qstr($s,$magic_quotes=false)
{
if (!$magic_quotes) {
if ($this->replaceQuote[0] == ‘\\’){
// only since php 4.0.5
$s = adodb_str_replace(array(‘\\’,”\0″),array(‘\\\\’,”\\\0″),$s);
//$s = str_replace(“\0″,”\\\0″, str_replace(‘\\’,'\\\\’,$s));
}
return “‘”.str_replace(“‘”,$this->replaceQuote,$s).”‘”;
}
// undo magic quotes for ”
$s = str_replace(‘\\”‘,’”‘,$s);
if ($this->replaceQuote == “\\’”) // ‘ already quoted, no need to change anything
return “‘$s’”;
else {// change \’ to ” for sybase/mssql
$s = str_replace(‘\\\\’,'\\’,$s);
return “‘”.str_replace(“\\’”,$this->replaceQuote,$s).”‘”;
}
}
