找回密码
 免费注册

Object of class mysqli could not be converted to string in写PHP时遇到报错

[复制链接]
发表于 2023-2-1 13:47:54 | 显示全部楼层 |阅读模式
Object of class mysqli could not be converted to string in写PHP时遇到报错

检查一下代码:
  1.     function query($sql){
  2.         echo $sql;
  3.         $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
  4.    
  5.         return $query;
  6.     }
复制代码
mysqli_result是由mysqli_query返回的,所以错误应该在返回值上。

php5以上中不能直接将对象输出为字符串。

所以改一下返回值的类型就可以了。

  1.     function query($sql){
  2.         echo $sql;
  3.         $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
  4.         return  mysqli_fetch_array($query);
  5.         //return $query;
  6.     }
复制代码

用mysqli_fetch_array()函数以数组的形式返回。


QQ|Archiver|小黑屋|网站地图|深圳市金黑网络技术有限公司 ( 粤ICP备2021124338号|粤公网安备 44030702003689号 )

GMT+8, 2026-8-8 16:00 , Processed in 0.056707 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表