PHP 是否在pg_fetch_assoc()
内部运行
使用迭代器/游标,还是一次获取所有数据,网络方式?
会\PDO
使用光标吗?
我的上下文正在获取大量数据,我想知道它是作为一个整体提取还是逐行提取(或者当游标包含完整数据集的子集时,是逐行限制)。
PHP 是否在pg_fetch_assoc()
内部运行
使用迭代器/游标,还是一次获取所有数据,网络方式?
会\PDO
使用光标吗?
我的上下文正在获取大量数据,我想知道它是作为一个整体提取还是逐行提取(或者当游标包含完整数据集的子集时,是逐行限制)。
pg_fetch_assoc()
也没有。它是一个从 PHP 资源中获取关联数组的函数。例如,资源可以是调用的结果PQexecPrepared
。
在 API 级别 PHP-pgsql 没有游标函数。您可以尝试使用 PDO,如果您启用可滚动游标模式,它会模拟 PostgreSQL 的游标。有关prepare()
更多详细信息,请参阅。另一种选择是自己使用 SQL 游标语句。
这个答案解释了一点:php postgres from query to fetching rows in theory
这是PDO 源代码的链接,它负责用 SQL 语句模拟游标。
数据通过 $result 传递:
(取自pgsql.php
打开的文件(CTRL + Click
在 PHPStorm 中的函数名上)):
/**
* Fetch a row as an associative array
* @link https://php.net/manual/en/function.pg-fetch-assoc.php
* @param resource $result <p>
* PostgreSQL query result resource, returned by <b>pg_query</b>,
* <b>pg_query_params</b> or <b>pg_execute</b>
* (among others).
* </p>
* @param int $row [optional] <p>
* Row number in result to fetch. Rows are numbered from 0 upwards. If
* omitted or <b>NULL</b>, the next row is fetched.
* </p>
* @return array An array indexed associatively (by field name).
* Each value in the array is represented as a
* string. Database NULL
* values are returned as <b>NULL</b>.
* </p>
* <p>
* <b>FALSE</b> is returned if <i>row</i> exceeds the number
* of rows in the set, there are no more rows, or on any other error.
* @since 4.3
* @since 5.0
*/
function pg_fetch_assoc ($result, $row = null) {}
中的行$result
是一个编号的数组/对象,包含它拥有的所有数据。它只是返回该数组/对象中的行,因此它处理传递的游标中的任何数据。我们可以从上面代码中的一行得到这个(为了更好地阅读而格式化):
@param resource $result
PostgreSQL 查询结果资源,由
pg_query、pg_query_params 或 pg_execute 返回