PHP数据库调用出错!Fatal error: Call to a member function fetch_row() on a non-object in

PHP数据库调用出错!Fatal error: Call to a member function fetch_row() on a non-object in,第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 )

$result1->fetch_assoc()

$mysqli = new mysqli("localhost", "my_user", "my_password", "world")

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5"

if ($result = $mysqli->query($query)) {

/* fetch associative array */

while ($row = $result->fetch_assoc()) {

printf ("%s (%s)\n", $row["Name"], $row["CountryCode"])

}

/* free result set */

$result->close()

}

---------------------------------------------------

原形 array mysqli_fetch_assoc ( mysqli_result result )

<?php

$link = mysqli_connect("localhost", "my_user", "my_password", "world")

/* check connection */

if (mysqli_connect_errno()) {

printf("Connect failed: %s\n", mysqli_connect_error())

exit()

}

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5"

if ($result = mysqli_query($link, $query)) {

/* fetch associative array */

while ($row = mysqli_fetch_assoc($result)) {

printf ("%s (%s)\n", $row["Name"], $row["CountryCode"])

}

/* free result set */

mysqli_free_result($result)

}

/* close connection */

mysqli_close($link)

?>

你别混用阿,而且原形就一个参数,你给了俩


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9894976.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存