致命错误:调用成员函数pg_fetch_object()

时间:2013-10-26 19:05:30

标签: php html mysql

我是PHP的新手,我想在我的表格中显示一个名为music的列, 表名是作曲家, 但每次我发出错误: 致命错误:在第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";
        }

    ?>

2 个答案:

答案 0 :(得分:1)

  1. mysql_fetch_object返回对象作为结果。
  2. mysql_fetch_row返回数组
  3.  while($row = mysql_fetch_object($result)){
            $musicname = $row->composer;
            echo "$musicname";
            }
    

答案 1 :(得分:0)

pg_fetch_object更改为mysql_fetch_object