firebird 数据库列的结果只是无名的数字
Results from firebird DB columns are nameless just numbers
我正在使用以下代码查询我的 Firebird 数据库,但结果不包括列名,仅包括数字。这是我第一次使用 Firebird,我只使用了 MySQL。有没有办法获取列名而不是数字?
$dbh = ibase_connect($cdb, $this->session->userdata('client_username'), $this->session->userdata('client_password'), 'utf-8', '100');
$rid = ibase_query($dbh, $query);
$coln = ibase_num_fields($rid);
$dataArr = array();
while ($row = ibase_fetch_row ($rid)) {
$dataArr[] = $row;
}
结果:
Array
(
[0] => Array
(
[0] => 1
)
)
如何获取 [User_Id]
而不是 [0]
的列名?可能吗?
当您准备 查询 Firebird 时 returns 它的结果集信息,包括列数据类型和别名。使用fbird_field_info(...)
查询别名。
按照 Dharman in the comments, you need to use ibase_fetch_assoc
instead of ibase_fetch_row
的建议,使用列名(关联数组)获得结果。
根据 ibase_fetch_assoc
的记录:
fetches one row of data from the result. If two or more columns of the
result have the same field names, the last column will take
precedence. To access the other column(s) of the same name, you either
need to access the result with numeric indices by using
ibase_fetch_row() or use alias names in your query.
与ibase_fetch_row
相比:
Returns an array that corresponds to the fetched row, or false if
there are no more rows. Each result column is stored in an array
offset, starting at offset 0.
我正在使用以下代码查询我的 Firebird 数据库,但结果不包括列名,仅包括数字。这是我第一次使用 Firebird,我只使用了 MySQL。有没有办法获取列名而不是数字?
$dbh = ibase_connect($cdb, $this->session->userdata('client_username'), $this->session->userdata('client_password'), 'utf-8', '100');
$rid = ibase_query($dbh, $query);
$coln = ibase_num_fields($rid);
$dataArr = array();
while ($row = ibase_fetch_row ($rid)) {
$dataArr[] = $row;
}
结果:
Array
(
[0] => Array
(
[0] => 1
)
)
如何获取 [User_Id]
而不是 [0]
的列名?可能吗?
当您准备 查询 Firebird 时 returns 它的结果集信息,包括列数据类型和别名。使用fbird_field_info(...)
查询别名。
按照 Dharman in the comments, you need to use ibase_fetch_assoc
instead of ibase_fetch_row
的建议,使用列名(关联数组)获得结果。
根据 ibase_fetch_assoc
的记录:
fetches one row of data from the result. If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using ibase_fetch_row() or use alias names in your query.
与ibase_fetch_row
相比:
Returns an array that corresponds to the fetched row, or false if there are no more rows. Each result column is stored in an array offset, starting at offset 0.