Pra*_*sha 5 php zend-framework mysql-real-escape-string zend-db
我正在使用zend框架开发一个Web应用程序.对于select语句,我使用了以下方法.
例如:
public function getData($name)
{
$sql = "SELECT * from customer where Customer_Name = '$name'";
return $this->objDB->getAdapter()->fetchAll ($sql);
}
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,如果我将客户名称发送为:colvin's place,则查询失败.我知道这是因为单引号.
之前我用过addslashes PHP函数.但我发现这不是一个很好的方法.这次我使用mysql_real_escape_stringPHP函数.
问题在于警告说.
Warning</b>: mysql_real_escape_string() [<a href='function.mysql-real-escape-string'>function.mysql-real-escape-string</a>]: Access denied for user 'ODBC'@'localhost' (using password: NO)
这是因为该mysql_real_escape_string函数需要连接到打开的数据库mysql_connect.我的问题是如何在*Zend_DB*类中使用它.我总是需要使用自定义选择查询.如果可以,请欣赏您的其他建议.
谢谢
您可以使用以下quote()提供的功能Zend_Db:
http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.quoting.quote
| 归档时间: |
|
| 查看次数: |
9619 次 |
| 最近记录: |