Home > Backend Development > PHP Tutorial > 一个很奇怪的问题:同样的一条sql语句,在mysql中能查到记录,而在php中却查不到

一个很奇怪的问题:同样的一条sql语句,在mysql中能查到记录,而在php中却查不到

WBOY
Release: 2016-06-23 13:57:24
Original
1019 people have browsed it

具体如下:
mysql中数据表结构:


sql语句:
SELECT ID FROM tradeDetails WHERE userName = '李四' AND goodsID ='1'

php代码:

<?phpmysql_connect("localhost","root","root");mysql_query("set names utf-8");mysql_select_db("test");// 为方便说明问题,我把条件参数设为常量$querySql="SELECT ID FROM tradeDetails WHERE userName = '李四' AND goodsID ='1'"; $rs=mysql_query($querySql);$totalRows_myrs=mysql_num_rows($rs); echo $totalRows_myrs;?>
Copy after login


我将sql语句放到mysql中执行能查到1条记录,而php页面执行时,却不能查到记录。求解。


回复讨论(解决方案)

mysql_query("set names  utf8");

php文件的本身也要是utf8编码。

php文件的本身也要是 utf-8编码

前两位正解 ,嘿嘿 ,应该是编码的问题。。。

谢谢各位!在1楼版主的提示下,我才发现自已代码写错了,把utf-8改为utf8就好了! 分不多,我就不平均地分一下了 呵呵

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