简体   繁体   中英

php - mysql_real_escape_string and varchar issue

I'm using mysql_query in php and my problem is, when I pass a string with mysql_real_escape_string, it returns no results. when I remove the mysql_real_escape_string function, it works perfectly. This is my code:

public function select_user($user) {  
 $sql = "SELECT * FROM users WHERE username LIKE '".mysql_real_escape_string($user)."'";
 return $this->query($sql);
} 

note that $this->query is a function for querying the statement.

most likely there is no mysql connection established for the mysql_* functions and thus mysql_real_escape_string returns an empty string.

You have to use whatever formatting/binding facilities allowed by the API you're using for your query() method.

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