首页 > 解决方案 > codeigniter 获取最近查询的 postgres 字段类型

问题描述

我正在使用带有codeigniter的php。我喜欢在我的 postgres 数据库上运行 sql 查询,我不仅对结果感兴趣,而且对字段类型也感兴趣。

有php函数:pg_field_type (resource $result, int $field_number)

那应该返回我需要的信息,但我想知道是否有办法将它与 codeigniter db 类一起使用?

版本

postgres:9.4 代码点火器:3.1.10

例子

$res = $this->db->query("select * from foobar);

返回我这样的结果对象:

CI_DB_postgre_result Object
(
[conn_id] => Resource id #2
[result_id] => Resource id #5
[result_array] => Array
    (
    )

[result_object] => Array
    (
    )

[custom_result_object] => Array
    (
    )

[current_row] => 0
[num_rows] => 
[row_data] => 
)

Resource id #5 将是我的资源,但如何访问它?

最好的,

d。

标签: phppostgresqlcodeigniter

解决方案


$res = $this->db->query("select * from foobar);
$data =  $res->result();
print_r( $data ) // will print all the rows

//return $data // will return data to the controller 

推荐阅读