php-doc-en/reference/pgsql/functions/pg-execute.xml
2005-03-20 08:54:31 +00:00

121 lines
4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
<refentry id="function.pg-execute">
<refnamediv>
<refname>pg_execute</refname>
<refpurpose>Execute a previously prepared query</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>resource</type><methodname>pg_execute</methodname>
<methodparam><type>string</type><parameter>stmtname</parameter></methodparam>
<methodparam><type>array</type><parameter>params</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>resource</type><methodname>pg_execute</methodname>
<methodparam><type>resource</type><parameter>connection</parameter></methodparam>
<methodparam><type>string</type><parameter>stmtname</parameter></methodparam>
<methodparam><type>array</type><parameter>params</parameter></methodparam>
</methodsynopsis>
<para>
<function>pg_execute</function> returns a query result resource if
the named prepared query could be executed with the given parameters.
It returns &false; on failure or if
connection is not a valid connection. Details about the error can
be retrieved using the <function>pg_last_error</function>
function if connection is valid.
<function>pg_execute</function> executes a previously prepared
query on the
<parameter>connection</parameter> resource with the specified
parameters. It is identical to <function>pg_query_params</function>
except that it takes the name of a previously prepared query instead
of an actual query. The
<parameter>connection</parameter> must be a valid connection that
was returned by <function>pg_connect</function> or
<function>pg_pconnect</function>. The return value of this
function is an query result resource to be used to access the
results from other PostgreSQL functions such as
<function>pg_fetch_array</function>.
<note>
<simpara>
<parameter>connection</parameter> is an optional parameter for
<function>pg_execute</function>. If
<parameter>connection</parameter> is not set, default
connection is used. Default connection is the last connection
made by <function>pg_connect</function> or
<function>pg_pconnect</function>.
</simpara>
<simpara>
Although <parameter>connection</parameter> can be omitted, it
is not recommended, since it could be a cause of hard to find
bug in script.
</simpara>
</note>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Using <function>pg_execute</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Connect to a database named "mary"
$dbconn = pg_connect("dbname=mary");
// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
// Execute the same prepared query, this time with a different parameter
$result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
?>
]]>
</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_prepare</function></member>
<member><function>pg_send_execute</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
-->