Object of class mysqli could not be converted to string in写PHP时遇到报错
Object of class mysqli could not be converted to string in写PHP时遇到报错检查一下代码:
function query($sql){
echo $sql;
$query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
return $query;
}mysqli_result是由mysqli_query返回的,所以错误应该在返回值上。
php5以上中不能直接将对象输出为字符串。所以改一下返回值的类型就可以了。 function query($sql){
echo $sql;
$query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
returnmysqli_fetch_array($query);
//return $query;
}用mysqli_fetch_array()函数以数组的形式返回。
页:
[1]