PHP does not return all the results of a query to Oracle when there are many records

3

I'm making queries from PHP to an Oracle database.

The problem is that when the database has few records (5 for example), when I go through the oci_fetch_array function, it returns them without problem, but when it is 100 records it returns me null .

This is the code:

$sql = oci_parse($this->db, "SELECT * FROM EMPRESAS ORDER BY ID DESC");
oci_execute($sql);

    $array = [];
    while ($row = oci_fetch_array($sql, OCI_ASSOC + OCI_RETURN_NULLS)) {
        array_push($array, $row);
    }

    return $array ? $array : null;

It returns null because the array is empty.

Any idea what may be happening?

I have done debug and it does not enter the loop. $ row returns false.

I'm using Oracle database 11g Express and PHP 5.6.

I have also tried the oci_error () function and it returns false.

I do the same select from SQL Developer and it correctly returns all the rows.

    
asked by Isaac R 21.07.2017 в 12:24
source

1 answer

0

Try using oci_fetch_all , since this stores you immediately in an array.

$sql = oci_parse($this->db, "SELECT * FROM EMPRESAS ORDER BY ID DESC");
oci_execute($sql);

$nrows = oci_fetch_all($sql, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW);

echo "$nrows filas obtenidas<br>\n";
var_dump($res); // la variable $res ya traeria un array con la información

As a personal note I would also recommend you to start reviewing PDO.

    
answered by 21.07.2017 в 14:37