将Postgres数据库转换为JSON时获取null

时间:2014-04-18 17:58:35

标签: php json postgresql

我试图用PHP转换Postgres数据库中的表。问题是,当我运行脚本时,我得到null,并且没有提取任何数据。

这是我的代码:

<?php 
$connection = pg_connect("host=xxx port=5432 dbname=xxxxx user=xxxxx password=xxxxxxxxx");

$result = pg_query('SELECT * FROM deals'); 


$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode(array_values(pg_fetch_all($result)));
?>

这是代码的实际链接:

http://send.easyrent-brasil.com/api.php

1 个答案:

答案 0 :(得分:0)

您是否尝试过删除<{p>}之类的null

$result = pg_query('SELECT * FROM deals WHERE *filed* != 'null');

$result = pg_query('SELECT * FROM deals WHERE *filed* != '');