gpt4 book ai didi

php - fatal error : Call to a member function pg_fetch_object()

转载 作者:行者123 更新时间:2023-11-29 13:29:59 24 4
gpt4 key购买 nike

我是 PHP 新手,我想显示表中名为音乐的一列,表名是 Composer ,但每次我都会报错: fatal error :在第 35 行/Applications/XAMPP/xamppfiles/htdocs/admin/music.php 中的非对象上调用成员函数 pg_fetch_object()

这是我的代码:

<?php

$host ="localhost"; //host
$username="root"; //username
$password ="";//password of the database
$dbName="wikiseda";//database Name
$tbl_name="users";
$tbl_music="music";
//______________________________
$connection=mysql_connect("$host","$username","$password") or die("can't connect sorry");
mysql_select_db($dbName,$connection) or die('can not select db');

$sql ="SELECT * FROM music";
$result = mysql_query($sql) or die(mysql_error());
while($row = $result-> pg_fetch_object()){
$musicname = $row->composer;
echo "$musicname";
}

?>

最佳答案

  1. mysql_fetch_object 返回对象作为结果。
  2. mysql_fetch_row 返回数组作为结果

尝试

 while($row = mysql_fetch_object($result)){
$musicname = $row->composer;
echo "$musicname";
}

关于php - fatal error : Call to a member function pg_fetch_object(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19610726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com