mysqli查询数据始终为null
代码如下,测试好多遍,始终不知道原因,Sql语句在Navicat里边有查询结果,大家帮我看看:
function db_connect(){
$db=new mysqli("127.0.0.1", "root","admin159753","51dm","utf8");
$db->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);
------解决思路----------------------