Ângelo Rigo
Ângelo Rigo

Reputation: 2155

CakePHP 2.5 rawQuery how to loop the results?

Using CakePHP 2.5 rawQuery, which is the best way to iterate through the results?

I am using native PHP oci_execute then oci_fetch_array.

Is there any CakePHP way that can do the same?

$results = $db->rawQuery($data_sql);
$search_results = oci_execute($results);
while ( ( $row = oci_fetch_array($search_results, OCI_BOTH ) ) != false)
{

Upvotes: 0

Views: 320

Answers (1)

Inigo Flores
Inigo Flores

Reputation: 4469

Method DboSource::rawQuery() returns a PDOStatement object if the query was successful.

You can use the standard methods provided by PHP to deal with PDOStatement objects.

This should work:

$results = $db->rawQuery($data_sql);
foreach ($results as $row){
    //code inside loop
}

For further information, see:

Upvotes: 1

Related Questions