简体   繁体   中英

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 . I am using cakePHP. I tried using

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

I tried even mysql_real_escape_string() also.

My column name is close_%

But still it didn't work. How to byepass the column name with % symbol in query using 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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