Home  >  Article  >  Backend Development  >  php查询mysql数据库 查询条件替中文字符串变量时无法查询

php查询mysql数据库 查询条件替中文字符串变量时无法查询

WBOY
WBOYOriginal
2016-06-13 11:09:56775browse

php查询mysql数据库 查询条件为中文字符串变量时无法查询
$temp2 ='十年';
mysql_query("SET NAMES GBK");
$res = mysql_query("select songer_name from song_tab where song_name ='十年'");
可以查询出结果 
但是

$temp2 ='十年';
mysql_query("SET NAMES GBK");
$res = mysql_query("select songer_name from song_tab where song_name =$temp2");
就不行了 请问怎么解决啊
------解决方案--------------------
$temp2 左右两边加单引号,最好先addslashes()。
------解决方案--------------------
引号!
$res = mysql_query("select songer_name from song_tab where song_name ='$temp2'");

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn