我正在尝试在MySQL,Postgres,SQLServer和Oracle上使用PDO :: FETCH_LAZY创建基准。
因此(在Oracle上)我创建了此表:
CREATE TABLE "TESTE"
( "ID" NUMBER(*,0),
"DATETIME" DATE DEFAULT SYSDATE,
"CHANNEL" NUMBER(*,0) DEFAULT NULL,
"VALUE" FLOAT(5)
)
并使用此过程:
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;
并尝试过此代码:
<?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];
}
在MySQL,Postgres和SQLServer上工作得很好,但是Oracle使用PDO返回的count()仅返回false或0。但是,出于奇怪的原因,在SQL Developer上效果很好(count()返回1000000)。
那么,在PHP PDO上使用Oracle XE有什么限制?还有其他方法可以解决这个问题吗?还是pdo_oci错误?