积垢OOPHP+;我的函数列表中的Postgres错误

积垢OOPHP+;我的函数列表中的Postgres错误,php,postgresql,Php,Postgresql,我正在用PHP OO开发一个CRUD应用程序,我在postgres中的这个列表函数有一个问题,在我的PHP页面HTML中显示了一个错误: (!)警告:为C:\wamp\www\CRUD Postgres\pessoa.php第47行中的foreach()提供的参数无效 功能: function busca() { require_once ('db_conecta.php'); $query = ("SELECT * FROM pessoas "); $st

我正在用PHP OO开发一个CRUD应用程序,我在postgres中的这个列表函数有一个问题,在我的PHP页面HTML中显示了一个错误:

(!)警告:为C:\wamp\www\CRUD Postgres\pessoa.php第47行中的foreach()提供的参数无效

功能:

function busca() {
    require_once ('db_conecta.php');       
    $query = ("SELECT * FROM pessoas ");
    $stmt = pg_query($con, $query);
    $resultados = pg_fetch_array($stmt);
    $pessoas = array();
    foreach ($resultados as $item) {
        $pessoa = new Pessoa();
        $pessoa -> setId($item['id']);
        $pessoa -> setNome($item['nome']);
        $pessoa -> setFone($item['fone']);
        $pessoa -> setEmail($item['email']);
        array_push($pessoas, $pessoa);
    }
    return $pessoas;
}

pg_fetch_数组
将返回
false
如果没有要检索的行,请尝试在
foreach
之前输出值

它也只返回一行。也许您打算使用
pg\u fetch\u all