mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-25 13:28:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@238929 c90b9560-bf6c-de11-be94-00142212c4b1
173 lines
4.7 KiB
XML
173 lines
4.7 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.15 $ -->
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
|
|
<refentry xml:id="function.pg-query" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_query</refname>
|
|
<refpurpose>Execute a query</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>resource</type><methodname>pg_query</methodname>
|
|
<methodparam><type>string</type><parameter>query</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<methodsynopsis>
|
|
<type>resource</type><methodname>pg_query</methodname>
|
|
<methodparam><type>resource</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>query</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_query</function> executes the <parameter>query</parameter>
|
|
on the specified database <parameter>connection</parameter>.
|
|
</para>
|
|
<para>
|
|
If an error occurs, and &false; is returned, details of the error can
|
|
be retrieved using the <function>pg_last_error</function>
|
|
function if the connection is valid.
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<simpara>
|
|
Although <parameter>connection</parameter> can be omitted, it
|
|
is not recommended, since it can be the cause of hard to find
|
|
bugs in scripts.
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
This function used to be called <function>pg_exec</function>.
|
|
<function>pg_exec</function> is still available for compatibility
|
|
reasons, but users are encouraged to use the newer name.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>connection</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
PostgreSQL database connection resource. When
|
|
<parameter>connection</parameter> is not present, the default connection
|
|
is used. The default connection is the last connection made by
|
|
<function>pg_connect</function> or <function>pg_pconnect</function>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>query</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
The SQL statement or statements to be executed. When multiple statements are passed to the function,
|
|
they are automatically executed as one transaction, unless there are explicit BEGIN/COMMIT commands
|
|
included in the query string. However, using multiple transactions in one function call is not recommended.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
A query result resource on success, or &false; on failure.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>pg_query</function> example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
if (!$conn) {
|
|
echo "An error occured.\n";
|
|
exit;
|
|
}
|
|
|
|
$result = pg_query($conn, "SELECT author, email FROM authors");
|
|
if (!$result) {
|
|
echo "An error occured.\n";
|
|
exit;
|
|
}
|
|
|
|
while ($row = pg_fetch_row($result)) {
|
|
echo "Author: $row[0] E-mail: $row[1]";
|
|
echo "<br />\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Using <function>pg_query</function> with multiple statements</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
|
|
// these statements will be executed as one transaction
|
|
|
|
$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
|
|
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";
|
|
$query .= "UPDATE authors SET author=NULL WHERE id=3;";
|
|
|
|
pg_query($conn, $query);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_connect</function></member>
|
|
<member><function>pg_pconnect</function></member>
|
|
<member><function>pg_fetch_array</function></member>
|
|
<member><function>pg_fetch_object</function></member>
|
|
<member><function>pg_num_rows</function></member>
|
|
<member><function>pg_affected_rows</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:"../../../../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
|
|
-->
|