开发者

Why dose PHP Mysqli_fetch_row work but not Mysqli_fetch_assoc on my server?

I know a little about how to debug and deal with errors when using PHP. However, this one is an an anomaly.

After I successfully create a connection to my Mysql database via mysqli, I try to get the result from it.

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

$num_results = $result->num_rows;  
echo "<p> Number of books found: ".$num_results."</p>";
$row = $result->fetch_assoc();  //no problem if I use fetch_row

The weird thing happens, the whole page collapses and the browser shows "the webpage can not be displayed".

I try to identify the problem and replace the line "$row = $result->fetch_assoc();" with "$row = $result->fetch_row();" and it successfully fetch the result from database (I didn't show the above/below code here for the sake of brevity).

It turns out that "fetch_array" and "fetch_object" failed as well. The other part of coding works just fine once i comment it out. So i开发者_高级运维 just wonder how could fetch_row works but "fetch_array/object/assoc" seems to make the whole page collapse (not just the function itself and there is no PHP error message as well).


You don't see errors it's because you don't have enabled errors, I believe you are not using the right functions to call fetch array or fetch association, search in your class for the right function, as I believe fetch_array(), fetch_assoc() throws Fatal Error in php.

Search in your apache logs.

Try to add in your php file on top:

ini_set('display_errors', E_ALL);
error_reporting(E_ALL);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜