donglu1971 2012-10-09 07:30
浏览 133
已采纳

PHP5 + PostgreSQL - pg_fetch_row()返回字符串而不是数组

PHP5 + PostgreSQL (ubuntu 12.04) according to the doco returns an array for pg_fetch_row(). By my test results indicate that it's returning a string, is there some configuration option for this?

$db = openDatabase(<blah>);
$query = "SELECT (id,serial,tag) FROM devices ORDER BY tag ASC";
$result = pg_query($db,$query);
if ($result)
{
    while ($row = pg_fetch_row($result))
        echo "IN: $row[0] - $row[1] - $row[2]";
}

I expect to see

IN: <value> - <value> - <value>

But I get

IN: (<value>,<value>,<value>) - - 

I guess this means pg_fetch_row() is returning a string not an array?!

e.g. the actual run:

IN: (10,7426573,________) - - 
IN: (7,6862,FMUX-TAG) - - 
IN: (9,6914082,L6) - - 

It seems a simple problem, but I can't find an answer. I know I can parse the result, but that's kludgey.

  • 写回答

2条回答 默认 最新

  • doujie4344 2012-10-09 08:18
    关注

    Change SELECT (id,serial,tag) into SELECT id,serial,tag and you're done.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条