本文介绍了CodeIgniter 3.1.7 unbuffered_row()返回NULL,但row()有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从查询结果中输出CSV. dbutil-> csv_from_result()应该可以工作,但是它仅返回列标题.不包含任何数据.

I am attempting to output a CSV from a query result. dbutil->csv_from_result() should work, but it only returns the column headers. No data is included.

我跟踪到使用 unbuffered_row() system/database/DB_utility.php .

任何对 unbuffered_row()的调用都会返回 NULL .如果将其更改为 row(),则会得到结果.如果我使用 unbuffered_row('array') unbuffered_row('object')

Any calls to unbuffered_row() return NULL. If I change it to row(), I get a result. It makes no difference if I use unbuffered_row('array') or unbuffered_row('object')

为什么 row()起作用,而 unbuffered_row()却不起作用?

Why does row() work but unbuffered_row() does not?

这是CI中的错误还是我遗漏了一些东西?

Is this a bug in CI or am I missing something?

row('array')似乎也不起作用.

似乎调用 $ query-> result()会破坏 dbutil-> csv_from_result($ query).您显然无法遍历查询结果,然后将结果保存到CSV文件中.这在CI 2中是 .

It seems that calling $query->result() spoils dbutil->csv_from_result($query). You apparently cannot iterate through query results AND then save the results in a CSV file. This was possible in CI 2.

是否可以显示查询结果并保存CSV,而无需两次运行查询?

推荐答案

我也遇到了类似的问题,并发现了以下问题:

I have faced similar problem and found this:

我有这个查询:

$query = $this->db->query("SELECT * FROM tablename");
print_r($query);

然后我得到了,并且 unbuffered_row 正常工作:

Then I get this and unbuffered_row works fine:

CI_DB_oci8_result Object
(
    [stmt_id] => Resource id #106
    [curs_id] =>
    [limit_used] =>
    [commit_mode] => 32
    [conn_id] => Resource id #91
    [result_id] => 1
    [result_array] => Array
        (
        )

    [result_object] => Array
        (
        )

    [custom_result_object] => Array
        (
        )

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

但是,如果我在获得不同的 CI_DB_oci8_result 对象之前调用 $ query-> num_rows(),并且 unbuffered_row 无法返回空

BUT if I call $query->num_rows() before I get a different CI_DB_oci8_result object and unbuffered_row didn't work returning null

$query = $this->db->query("SELECT * FROM tablename");
echo $query->num_rows();
print_r($query);

希望这对某人有所帮助.

Hope this help somebody.

这篇关于CodeIgniter 3.1.7 unbuffered_row()返回NULL,但row()有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:33