php-doc-en/reference/cubrid/functions/cubrid-execute.xml
Esen Sagynov 809cf05852 APIS-160
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@324612 c90b9560-bf6c-de11-be94-00142212c4b1
2012-03-29 05:16:21 +00:00

207 lines
6.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.cubrid-execute" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>cubrid_execute</refname>
<refpurpose>Execute a prepared SQL statement</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>resource</type><methodname>cubrid_execute</methodname>
<methodparam><type>resource</type><parameter>conn_identifier</parameter></methodparam>
<methodparam><type>string</type><parameter>sql</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>option</parameter></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>bool</type><methodname>cubrid_execute</methodname>
<methodparam><type>resource</type><parameter>request_identifier</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>option</parameter></methodparam>
</methodsynopsis>
<para>
The <function>cubrid_execute</function> function is used to execute the
given SQL statement. It executes the query by using
<parameter>conn_identifier</parameter> and SQL, and then returns the
request identifier created. It is used for simple execution of query,
where the parameter binding is not needed. In addition, the
<function>cubrid_execute</function> function is used to execute the
prepared statement by means of <function>cubrid_prepare</function> and
<function>cubrid_bind</function>. At this time, you need to specify
arguments of <parameter>request_identifier</parameter> and
<parameter>option</parameter>.
</para>
<para>
The <parameter>option</parameter> is used to determine whether to get OID
after query execution and whether to execute the query in synchronous or
asynchronous mode. CUBRID_INCLUDE_OID and CUBRID_ASYNC (or
CUBRID_EXEC_QUERY_ALL if you want to execute multiple SQL statements) can
be specified by using a bitwise OR operator. If not specified, neither of
them isselected. If the flag CUBRID_EXEC_QUERY_ALL is set, a synchronous
mode (sync_mode) is used to retrieve query results, and in such cases the
following rules are applied:
</para>
<para>
<simplelist>
<member>The return value is the result of the first query.</member>
<member>
If an error occurs in any query, the execution is processed as a
failure.
</member>
<member>
In a query composed of q1 q2 q3, if an error
occurs in q2 after q1 succeeds the execution, the result of q1 remains
valid. That is, the previous successful query executions are not rolled
back when an error occurs.
</member>
<member>
If a query is executed successfully, the result of the second query can
be obtained using <function>cubrid_next_result</function>.
</member>
</simplelist>
</para>
<para>
If the first argument is <parameter>request_identifier</parameter> to
execute the <function>cubrid_prepare</function> function, you can specify
an option, CUBRID_ASYNC only.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>conn_identifier</parameter></term>
<listitem><para>Connection identifier.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>sql</parameter></term>
<listitem><para>SQL to be executed.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>option</parameter></term>
<listitem><para>Query execution option CUBRID_INCLUDE_OID, CUBRID_ASYNC, CUBRID_EXEC_QUERY_ALL.</para></listitem>
</varlistentry>
<varlistentry>
<term><parameter>request_identifier</parameter></term>
<listitem><para><function>cubrid_prepare</function> identifier.</para></listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Request identifier, when process is successful and first param is
conn_identifier; &true;, when process is successful and first argument is
request_identifier.
</para>
<para>
&false;, when process is unsuccessful.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Add new option CUBRID_EXEC_QUERY_ALL.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>cubrid_execute</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$conn = cubrid_connect("localhost", 33000, "demodb");
$result = cubrid_execute($conn, "SELECT code FROM event WHERE name='100m Butterfly' and gender='M'", CUBRID_ASYNC);
$row = cubrid_fetch_array($result, CUBRID_ASSOC);
$event_code = $row["code"];
cubrid_close_request($result);
$history_req = cubrid_prepare($conn, "SELECT * FROM history WHERE event_code=?");
cubrid_bind($history_req, 1, $event_code, "number");
cubrid_execute($history_req);
printf("%-20s %-9s %-10s %-5s\n", "athlete", "host_year", "score", "unit");
while ($row = cubrid_fetch_array($history_req, CUBRID_ASSOC)) {
printf("%-20s %-9s %-10s %-5s\n",
$row["athlete"], $row["host_year"], $row["score"], $row["unit"]);
}
cubrid_close_request($history_req);
cubrid_disconnect($conn);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
athlete host_year score unit
Phelps Michael 2004 51.25 time
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>cubrid_prepare</function></member>
<member><function>cubrid_bind</function></member>
<member><function>cubrid_next_result</function></member>
<member><function>cubrid_close_request</function></member>
<member><function>cubrid_commit</function></member>
<member><function>cubrid_rollback</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
-->