drlu11748 2010-02-11 14:42
浏览 76
已采纳

如何使用PHP ADOdb获取“字段名称”?

I'm using PHP ADOdb and I can get the result set:

$result = &$db->Execute($query);

How do I get the field names from that one row and loop through it?

(I'm using access database if that matters.)

  • 写回答

5条回答 默认 最新

  • duanhui1869 2010-02-11 14:55
    关注

    It will depend on your fetch mode - if you setFetchMode to ADODB_FETCH_NUM (probably the default) each row contains a flat array of columns. If you setFetchMode to ADODB_FETCH_ASSOC you get an associative array where you can access each value by a key. The following is taken from ADODB documentation - http://phplens.com/lens/adodb/docs-adodb.htm#ex1

    $db->SetFetchMode(ADODB_FETCH_NUM);
    $rs1 = $db->Execute('select * from table');
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    $rs2 = $db->Execute('select * from table');
    
    print_r($rs1->fields); # shows array([0]=>'v0',[1] =>'v1')
    print_r($rs2->fields); # shows array(['col1']=>'v0',['col2'] =>'v1')
    

    To loop through a set of results:

    $result = &$db->Execute($query);
    foreach ($result as $row) {
        print_r($row);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!