PHP数据库调用出错怎么办?
functionRand_news(){$mysqli=newmysqli("localhost","root","","nimei",3306);$query_news...
function Rand_news() {
$mysqli = new mysqli ( "localhost", "root", "", "nimei", 3306 );
$query_news = "select id,title,content from content where type=0 order by id desc LIMIT 1";
$result_news = $mysqli->query ( $query_news );
list ( $id,$title,$content ) = $result_news->fetch_row ();
$news_content[0][0]=trim($title);
$news_content[0][1] = trim(str_replace("
","
",$content));
$query_news = "update nimei.content set type=1 where id='$id'";
$result_news = $mysqli->query ( $query_news );
return $news_content;
}
调用nimei数据库中表content的id,title,content 展开
$mysqli = new mysqli ( "localhost", "root", "", "nimei", 3306 );
$query_news = "select id,title,content from content where type=0 order by id desc LIMIT 1";
$result_news = $mysqli->query ( $query_news );
list ( $id,$title,$content ) = $result_news->fetch_row ();
$news_content[0][0]=trim($title);
$news_content[0][1] = trim(str_replace("
","
",$content));
$query_news = "update nimei.content set type=1 where id='$id'";
$result_news = $mysqli->query ( $query_news );
return $news_content;
}
调用nimei数据库中表content的id,title,content 展开
1个回答
展开全部
遇见这种情况:“Fatal error: Call to a member function fetch_row() on a non-object”
然后显示出:“严重错误:调用fetch_row()的不是一个对象”。
就要立即开始检查 :
首先,来执行代码$result_news = $mysqli->query ( $query_news );
第二步开始检查结果是否正确,也就是说,看 $result_news 是否为同一个对象,写下代码: print_r($result_news)来查看;
正确结果为: mysqli_result Object ( [current_field] => 0 [field_count] => 8 [lengths] => [num_rows] => 1 [type] => 0 )
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询