1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 15:12:20 +01:00
Files
archived-doc-zh/reference/pgsql/functions/pg-fetch-array.xml
Dallas Wang 36dfbc9069 updated
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@117801 c90b9560-bf6c-de11-be94-00142212c4b1
2003-02-24 07:50:52 +00:00

102 lines
3.3 KiB
XML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="gb2312"?>
<!-- $Revision: 1.3 $ -->
<!-- $Author: dallas $ -->
<!-- EN-Revision: 1.7 Maintainer: dallas Status: ready -->
<refentry id="function.pg-fetch-array">
<refnamediv>
<refname>pg_fetch_array</refname>
<refpurpose>提取一行作为数组</refpurpose>
</refnamediv>
<refsect1>
<title>说明</title>
<methodsynopsis>
<type>array</type><methodname>pg_fetch_array</methodname>
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>row</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>result_type</parameter></methodparam>
</methodsynopsis>
<para>
<function>pg_fetch_array</function> 返回一个与所提取的行tuples/records相一致的数组。如果如果没有更多行可供提取则返回 &false;
</para>
<para>
<function>pg_fetch_array</function><function>pg_fetch_row</function> 的扩展版本。在返回的数组中不仅以数字索引方式存放数据(字段编号),默认情况下还用字段名做索引存放数据(字段名)。
</para>
<para>
<parameter>row</parameter> 是想要取得的行(记录)的编号。第一行为 0。
</para>
<para>
<parameter>result_type</parameter> 是可选参数,控制着怎样初始化返回值。<parameter>result_type</parameter>
是一个常量,可以有以下取值:<constant>PGSQL_ASSOC</constant><constant>PGSQL_NUM</constant>
<constant>PGSQL_BOTH</constant>。取值为 <constant>PGSQL_ASSOC</constant>
<function>pg_fetch_array</function> 返回用字段名作为键值索引的关联数组,取值为
<constant>PGSQL_NUM</constant> 时用字段编号作为键值,取值为
<constant>PGSQL_BOTH</constant> 时则同时用两者作为键值。默认值是 <constant>PGSQL_BOTH</constant>
<note>
<para>
<parameter>result_type</parameter> 是在 PHP 4.0 中才加入的参数。
</para>
</note>
</para>
<para>
<function>pg_fetch_array</function> 并不明显比使用 <function>pg_fetch_row</function> 慢,而且在使用中提供了更大的方便。
</para>
<para>
<example>
<title>PostgreSQL fetch array</title>
<programlisting role="php">
<![CDATA[
<?php
$conn = pg_pconnect ("dbname=publisher");
if (!$conn) {
echo "An error occured.\n";
exit;
}
$result = pg_query ($conn, "SELECT * FROM authors");
if (!$result) {
echo "An error occured.\n";
exit;
}
$arr = pg_fetch_array ($result, 0, PGSQL_NUM);
echo $arr[0] . " <- array\n";
$arr = pg_fetch_array ($result, 1, PGSQL_ASSOC);
echo $arr["author"] . " <- array\n";
?>
]]>
</programlisting>
</example>
</para>
<para>
参见 <function>pg_fetch_row</function><function>pg_fetch_object</function> 以及 <function>pg_fetch_result</function>
</para>
<note>
<para>
从 4.1.0 开始,<parameter>row</parameter> 成为可选参数。每次调用 <function>pg_fetch_array</function>,内部的行计数器都会加一。
</para>
</note>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->