php - 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?
解决方案
推荐阅读
- django - 如何在 Django 查询中应用多个过滤器而不知道某些过滤器是否为空
- vue.js - 我可以自定义 Vue.js 构建过程来运行我自己的终端命令吗?
- python - 在 Python 请求中获取“403 客户端错误:需要 SNI”
- python - 如何将我的 Tkinter 程序保存在文本文件中(包括复选框)
- serial-port - 模拟电脑上的com口被其他电脑识别
- android - 如何在控制台/命令行中自动扩展 logcat 错误?
- c++ - 使用 C++ obj/Release/MyApplication.o 在 CodeBlocks 上编译错误:Ubuntu 20.04 下没有此类文件或目录
- python - 如何使用“动态”词法分析器在基于 Lark 的解析器中“捕获”终端
- c# - 多个数据从数据库显示到同一个视图中
- excel - 使用 VBA 在数据透视表中创建计算字段