Skip to main content
 首页 » 编程设计

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

2022年07月19日184qq号

$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");
就不行了

$res = mysql_query("select songer_name from song_tab where song_name ='$temp2'");

     或 ‘{$temp2'}’都可以


本文参考链接:https://www.cnblogs.com/xihong2014/p/4370308.html