Php cannot query mysql database when the query condition is a Chinese string variable
Source: Internet
Author: User
$ Temp2 & nbsp; = 'ten years '; mysql_query ("SET & nbsp; NAMES & nbsp; GBK") cannot be queried when the query condition of the php mysql database is a Chinese string variable "); $ res & nbsp; = & nbsp; mysql_query ("select & nbsp; songer_name & nbsp; fro php cannot be queried when the mysql database query condition is a Chinese string variable
$ Temp2 = 'Ten year ';
Mysql_query ("set names gbk ");
$ Res = mysql_query ("select songer_name from song_tab where song_name = '10 '");
Query Results
However
$ Temp2 = 'Ten year ';
Mysql_query ("set names gbk ");
$ Res = mysql_query ("select songer_name from song_tab where song_name = $ temp2 ");
No. how can this problem be solved?
------ Solution --------------------
$ Temp2 is enclosed in single quotes on both sides. it is best to add addslashes () first ().
------ Solution --------------------
Quotation marks!
$ Res = mysql_query ("select songer_name from song_tab where song_name = '$ temp2 '");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service