首页 > 解决方案 > Oracle XE returns false fetching a table with 1 milion of lines using PHP

问题描述

I am trying to create a benchmark using PDO::FETCH_LAZY on MySQL, Postgres, SQLServer and Oracle.

So (on Oracle) I've created this table:

  CREATE TABLE "TESTE" 
   (    "ID" NUMBER(*,0), 
    "DATETIME" DATE DEFAULT SYSDATE, 
    "CHANNEL" NUMBER(*,0) DEFAULT NULL, 
    "VALUE" FLOAT(5)
   )

And used this procedure:

CREATE OR REPLACE PROCEDURE generate_data
AS
BEGIN
   DECLARE
      v_i NUMBER(10,0) := 0; 
   BEGIN
      WHILE v_i < 1000000 
      LOOP 
         BEGIN
            INSERT INTO teste
              ( datetime, value, channel )
              VALUES ( to_date('2010-01-01', 'yyyy-mm-dd')+trunc(dbms_random.value(1,1000)), ROUND(dbms_random.value * 100, 2), 1 );
            v_i := v_i + 1 ;
         END;
      END LOOP;
   END;
END;

And have tried this code :

<?php

ini_set("memory_limit", "-1");
include 'connection_oracle.php';

$statement   = $pdo->query('SELECT * FROM teste');
$inicio = new DateTime('now');
print_mem();
$i = 0;
while($registro = $statement->fetch(PDO::FETCH_LAZY)){
    $i++;
}
$fim = new DateTime('now');
$diff = $fim->diff($inicio);

echo "total : {$diff->format("%H:%I:%S:%F")} i: {$i}";
print_mem();

function print_mem(){
   $mem_usage = memory_get_usage();
   $mem_peak = memory_get_peak_usage();
   echo 'The script is now using: <strong>' . formatBytes($mem_usage) . '</strong> of memory.<br>';
   echo 'Peak usage: <strong>' . formatBytes($mem_peak) . '</strong> of memory.<br><br>';
}

function formatBytes($size){
  $base = log($size) / log(1024);
  $suffix = array("B", "KB", "MB", "GB", "TB");
  $f_base = floor($base);
  return round(pow(1024, $base - floor($base)), 1) . $suffix[$f_base];
}

Worked very well on MySQL, Postgres and SQLServer, but Oracle returns only false or 0 for count() using PDO. But, for strange reasons works well on SQL Developer (return 1000000 for count()).

So, is there any sort of limitation using Oracle XE on PHP PDO? Is there another way to surpass this or it is a pdo_oci bug?

标签: phporaclepdobenchmarkingoracle-xe

解决方案


推荐阅读