Welcome Guest, Not a member yet? Register   Sign In
Is there an issue with the dbutil class in 1.7?
#1

[eluser]Joe_Archer[/eluser]
Code:
function export(){
    $result = $this->subscribers->getsubscriberlist();
    $filename = "subscribers";
    header("Content-type: application/x-msdownload");
    header("Content-Disposition: attachment; filename=$filename.xls");
    echo($this->dbutil->csv_from_result($result));
}

returns
An Error Was Encountered

You must submit a valid result object

but I know the result object is valid as I'm using the same resultset returned by getsubscriberlist(); elsewhere in the app without problems.

Code:
print_r($result);
returns:
ci_db_mysql_result Object ( [conn_id] => Resource id #35 [result_id] => Resource id #47 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 2 [row_data] => )

I get the exact same results with
Code:
$this->dbutil->xml_from_result($result);
I'm using the exact same boilerplate code in a 1.6 app without any problems...
#2

[eluser]Joe_Archer[/eluser]
I'm now almost positive that this is 1.7 related, I just used the following test controller in 2 of my apps
Code:
class Test extends Controller{
    function Test(){
        parent::Controller();
    }
    
    function index(){
        $this->load->dbutil();
        $result = $this->db->query("SELECT * FROM subscribers");
        echo($this->dbutil->csv_from_result($result));
    }
}

works fine on the 1.6 app,
fails with

An Error Was Encountered

You must submit a valid result object

on 1.7....any ideas guys?
#3

[eluser]Joe_Archer[/eluser]
OK I have a fix that works for me.

on line 178 of system/database/DB_utility.php we have:
Code:
if ( ! is_object($query) OR ! method_exists($query, 'field_names'))

field_names does not exist in the result object, so i've changed it to
Code:
if ( ! is_object($query) OR ! method_exists($query, 'result_object'))

and all seems fine.

I guess somewhere in the changes to the database class, field_names got removed from the result object.

I'm not sure if my solution is the best, but it works for me.
#4

[eluser]eger[/eluser]
I was also having the same problem and your fix seems to work for me. However I am getting the names of the columns return in the csv at the beginning instead of just the data. I wonder if this is intentional or a side affect...
#5

[eluser]eger[/eluser]
I just found another post on this issue here: http://ellislab.com/forums/viewthread/95597/. It also appears to contain the correct fix as that method was deprecated. Instead replace field_names with list_fields. This appears to work for me also.
#6

[eluser]escape[/eluser]
I too have just encountered the same
Quote:You must submit a valid result object
error.

The Joe_Archer (thanks Joe) fix seems to work but will we know if this a bug and if it is how will it be addressed by CI?
#7

[eluser]Unknown[/eluser]
This error:
An Error Was Encountered

You must submit a valid result object

Also happens in CI 1.7.1 using the xml_from_result function in the Database Utility Class.

The fix can be copied from the csv_from_result function. Wink




Theme © iAndrew 2016 - Forum software by © MyBB