mirror of
https://github.com/php/doc-zh.git
synced 2026-03-24 07:02:15 +01:00
171 lines
4.9 KiB
XML
Executable File
171 lines
4.9 KiB
XML
Executable File
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- $Revision$ -->
|
||
<!-- EN-Revision: 39bb8a868935a56cfce438b0169e13c02c93211c Maintainer: HonestQiao Status: ready -->
|
||
<!-- CREDITS: mowangjuanzi -->
|
||
<refentry xml:id="function.pg-convert" xmlns="http://docbook.org/ns/docbook">
|
||
<refnamediv>
|
||
<refname>pg_convert</refname>
|
||
<refpurpose>
|
||
将关联的数组值转换为适合 SQL 语句的格式
|
||
</refpurpose>
|
||
</refnamediv>
|
||
|
||
<refsect1 role="description">
|
||
&reftitle.description;
|
||
<methodsynopsis>
|
||
<type class="union"><type>array</type><type>false</type></type><methodname>pg_convert</methodname>
|
||
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
||
<methodparam><type>string</type><parameter>table_name</parameter></methodparam>
|
||
<methodparam><type>array</type><parameter>values</parameter></methodparam>
|
||
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
<function>pg_convert</function> 检查 <literal>values</literal> 中的值并将其转换为为适用于
|
||
SQL 语句的值。<function>pg_convert</function> 的前提条件是现有的表 <literal>table_name</literal>
|
||
中具有的列至少有 <literal>values</literal> 中的单元那么多。<literal>table_name</literal>
|
||
中的字段名以及字段值必须匹配 <literal>values</literal>
|
||
中的索引,并且相应的数据类型必须兼容。成功时返回包含转换后的值的数组,否则返回 &false;。
|
||
</para>
|
||
<note>
|
||
<para>
|
||
接受 bool 值并转换为 PostgreSQL boolean 值。还支持 bool 值的字符串表示。&null;
|
||
转换为 PostgreSQL NULL。
|
||
</para>
|
||
</note>
|
||
</refsect1>
|
||
|
||
<refsect1 role="parameters">
|
||
&reftitle.parameters;
|
||
<para>
|
||
<variablelist>
|
||
<varlistentry>
|
||
<term><parameter>connection</parameter></term>
|
||
<listitem>
|
||
&pgsql.parameter.connection;
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>table_name</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
要转换类型的表名。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>values</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
要转换的数据。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>flags</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
<constant>PGSQL_CONV_IGNORE_DEFAULT</constant>、<constant>PGSQL_CONV_FORCE_NULL</constant>
|
||
或 <constant>PGSQL_CONV_IGNORE_NOT_NULL</constant> 的任意数量组合。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
</variablelist>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="returnvalues">
|
||
&reftitle.returnvalues;
|
||
<para>
|
||
转换值后的 <type>array</type>,&return.falseforfailure;。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="errors">
|
||
&reftitle.errors;
|
||
<para>
|
||
当字段的值或类型不能正确匹配 PostgreSQL 的类型时,会抛出 <classname>ValueError</classname> 或 <classname>TypeError</classname>。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="changelog">
|
||
&reftitle.changelog;
|
||
<informaltable>
|
||
<tgroup cols="2">
|
||
<thead>
|
||
<row>
|
||
<entry>&Version;</entry>
|
||
<entry>&Description;</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry>8.3.0</entry>
|
||
<entry>
|
||
当字段的值或类型不能正确匹配 PostgreSQL 的类型时,现在会抛出 <classname>ValueError</classname> 或
|
||
<classname>TypeError</classname> 错误;之前触发 <constant>E_WARNING</constant>。
|
||
</entry>
|
||
</row>
|
||
&pgsql.changelog.connection-object;
|
||
</tbody>
|
||
</tgroup>
|
||
</informaltable>
|
||
</refsect1>
|
||
|
||
<refsect1 role="examples">
|
||
&reftitle.examples;
|
||
<para>
|
||
<example>
|
||
<title><function>pg_convert</function> 示例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$dbconn = pg_connect('dbname=foo');
|
||
|
||
$tmp = array(
|
||
'author' => 'Joe Thackery',
|
||
'year' => 2005,
|
||
'title' => 'My Life, by Joe Thackery'
|
||
);
|
||
|
||
$vals = pg_convert($dbconn, 'authors', $tmp);
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="seealso">
|
||
&reftitle.seealso;
|
||
<para>
|
||
<simplelist>
|
||
<member><function>pg_meta_data</function></member>
|
||
<member><function>pg_insert</function></member>
|
||
<member><function>pg_select</function></member>
|
||
<member><function>pg_update</function></member>
|
||
<member><function>pg_delete</function></member>
|
||
</simplelist>
|
||
</para>
|
||
</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:"~/.phpdoc/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
|
||
-->
|