如何获得“字段名称"?使用PHP ADOdb? [英] How to get "field names" using PHP ADOdb?

查看:94
本文介绍了如何获得“字段名称"?使用PHP ADOdb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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?

(如果重要,我正在使用Access数据库.)

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

推荐答案

这将取决于您的提取模式-如果将FetchMode设置为ADODB_FETCH_NUM(可能是默认值),则每一行都包含一个平面的列数组.如果将FetchMode设置为ADODB_FETCH_ASSOC,则会得到一个关联数组,您可以在其中通过键访问每个值.以下内容摘自ADODB文档- http://phplens.com/lens/adodb/docs-adodb.htm#ex1

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')

要遍历一组结果:

$result = &$db->Execute($query);
foreach ($result as $row) {
    print_r($row);
}

这篇关于如何获得“字段名称"?使用PHP ADOdb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆