mysqli查询数据始终为null
代码如下,测试好多遍,始终不知道原因,sql语句在navicat里边有查询结果,大家帮我看看:
set_charset('utf8');
if (!$db) {
echo cloud not connect to database;
} else {
return $db;
}
}
$db=db_connect();
$type=首页驻站作品;
$query = select * from picture where type='首页驻站作品' order by chage_date desc;
$rs = $db->query($query);
if (mysqli_num_rows($rs)==0) {
echo num rows: 0;
}
if ($rs) {
echo rs;
} else {
echo 查询失败;
}
?>
------解决思路----------------------
$query = select * from picture where type='首页驻站作品' order by chage_date desc;
如果是同样的查询语句,很有可能是字符集的原因。
你php的文件编码是utf-8的么
------解决思路----------------------
$db=new mysqli(127.0.0.1, root,admin159753,51dm,utf8);
$query = select * from picture where type='首页驻站作品' order by chage_date desc;
$rs = $db->query($query);
------解决思路----------------------