简体   繁体   English

mysql_real_escape_string()在cakePHP中不起作用

[英]mysql_real_escape_string() not working in cakePHP

My query goes like this, 我的查询是这样的,

... ON (`Test`.`id` = `Form`.`close_`%)...

It throws error saying Syntax error or access violation: 1064 . 它引发错误,指出Syntax error or access violation: 1064 I am using cakePHP. 我正在使用cakePHP。 I tried using 我尝试使用

$field_name='close_%';
Sanitize::clean(utf8_encode($field_name),array('encode' => false));

I tried even mysql_real_escape_string() also. 我也尝试了mysql_real_escape_string()

My column name is close_% 我的列名是close_%

But still it didn't work. 但是仍然没有用。 How to byepass the column name with % symbol in query using CakePHP? 如何使用CakePHP在查询中用%符号绕过列名?

The Sanitize functions are for dealing with data, not column names, and mysql_real_escape_string , which is surely an act of desperation here, is designed for the same thing. Sanitize函数用于处理数据,而不是列名,并且mysql_real_escape_string (在这里肯定是绝望的行为)是为同一件事而设计的。

What you want to do is specify your column as: 您要做的是将您的列指定为:

`close_%`

Be sure to put the entire column name inside the back ticks. 确保将整个列名放在反勾内。

Honestly you should not have junk like this in your column names in the first place. 老实说,您首先不应在列名称中出现这样的垃圾。 It's just annoying. 真烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM