可捕获的致命错误:无法在 C 中将类 mysqli_result 的对象转换为字符串 [英] Catchable fatal error: Object of class mysqli_result could not be converted to string in C

查看:57
本文介绍了可捕获的致命错误:无法在 C 中将类 mysqli_result 的对象转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 PHP 和 Mysql 还很陌生,并且不断收到此错误

I am quite new in PHP and Mysql and keep getting this error

<?php  
$mysqli = new mysqli("localhost", "root", "root");
$mysqli->select_db("maturita");

$sql=$mysqli->query("SELECT name,description FROM `gallery`");

echo $sql;
?>

推荐答案

手册上说(https://secure.php.net/manual/en/mysqli.query.php):

失败时返回FALSE.对于成功的SELECTSHOWDESCRIBEEXPLAIN 查询mysqli_query() 将返回mysqli_result 对象.对于其他成功的查询,mysqli_query() 将返回 TRUE.

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

所以错误是因为PHP无法在echo函数中将mysqli_result对象转换为字符串.

So the error is because the PHP can not convert the mysqli_result object to string in the echo function.

您可以将代码更改为:

<?php  
$mysqli = new mysqli("localhost", "root", "root");
$mysqli->select_db("maturita");

$sql=$mysqli->query("SELECT name,description FROM `gallery`");

print_r($sql->fetch_all());
?>

结果将是结果的数组结构.

The result will be the array structure of the result.

mysqli_result等函数的说明可以在这里找到:https://secure.php.net/manual/en/class.mysqli-result.php

The description of mysqli_result and other function can be found here: https://secure.php.net/manual/en/class.mysqli-result.php

这篇关于可捕获的致命错误:无法在 C 中将类 mysqli_result 的对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆