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

WBOY
Release: 2016-06-13 11:09:56
Original
814 people have browsed it

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'");

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template