[英]Php and oracle OCI query
I have a prolem with this code 我有这个代码的问题
$stmt = oci_parse($db, $sql);
$isQueryOk = oci_execute($stmt);
if ($isQueryOk) {
while (($row = oci_fetch_assoc($stmt)) != false) {
array_push($results, $row);
}
echo json_encode($results);
} else {
$msg = "Error FETCHING ALL [$sql] on " . mb_strtoupper($dbTable) . "!";
}
The problem is that if oci_fetch_assoc($stmt)
return 20000 rows, the while (($row = oci_fetch_assoc($stmt)) != false) { array_push($results, $row); }
问题是如果
oci_fetch_assoc($stmt)
返回20000行,则while (($row = oci_fetch_assoc($stmt)) != false) { array_push($results, $row); }
while (($row = oci_fetch_assoc($stmt)) != false) { array_push($results, $row); }
takes to much time. while (($row = oci_fetch_assoc($stmt)) != false) { array_push($results, $row); }
花费太多的时间。 Is there a way that i can return echo json_encode($results);
有没有办法可以返回
echo json_encode($results);
without the WHILE cycle. 没有WHILE循环。
Thanks in advance. 提前致谢。
OR try to use another way to push your array. 或尝试使用其他方式推送您的阵列。 "Note: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function."
“注意:如果你使用array_push()向数组添加一个元素,最好使用$ array [] =因为这样就没有调用函数的开销。” http://php.net/manual/en/function.array-push.php
http://php.net/manual/en/function.array-push.php
$results[] = $row;
I'm not sure it'll be significantly faster, but as Marcos Sedrez wrote you can try using oci_fetch_all
. 我不确定它会明显加快,但正如Marcos Sedrez所写,你可以尝试使用
oci_fetch_all
。 You'll need to pass it a flag to return by row (instead of by column, the default) to match your current output format: 你需要传递一个标志来按行(而不是列,默认值)返回以匹配当前的输出格式:
oci_fetch_all($stmt, $output, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
json_encode($output);
See the documentation for further information. 有关详细信息,请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.