0
我在php中使用mysql_query,我的問題是,當我傳遞一個字符串與mysql_real_escape_string時,它不返回任何結果。當我刪除mysql_real_escape_string函數時,它完美地工作。這是我的代碼:php - mysql_real_escape_string和varchar問題
public function select_user($user) {
$sql = "SELECT * FROM users WHERE username LIKE '".mysql_real_escape_string($user)."'";
return $this->query($sql);
}
請注意$ this-> query是查詢語句的函數。
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit
你期待它做什麼?檢查包含字符串的用戶名嗎?你錯過了'%'符號。另外,不要使用'mysql_'擴展名,如上所述。 – Ryan
嗯,我想我必須去與MySQLi或PDO ....這似乎是一個更好的選擇......謝謝! –