mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-25 05:18:56 +00:00
151 lines
4.4 KiB
XML
151 lines
4.4 KiB
XML
![]() |
<?xml version="1.0" encoding="iso-8859-1"?>
|
||
|
<!-- $Revision: 1.1.1.1 $ -->
|
||
|
<refentry id="function.maxdb-stmt-prepare">
|
||
|
<refnamediv>
|
||
|
<refname>maxdb_stmt_prepare</refname>
|
||
|
<refpurpose>
|
||
|
Prepare a SQL statement for execution
|
||
|
</refpurpose>
|
||
|
</refnamediv>
|
||
|
<refsect1>
|
||
|
<title>Description</title>
|
||
|
<para>Procedure style:</para>
|
||
|
<methodsynopsis>
|
||
|
<type>bool</type><methodname>maxdb_stmt_prepare</methodname>
|
||
|
<methodparam><type>resource</type><parameter>stmt</parameter></methodparam>
|
||
|
<methodparam><type>string</type><parameter>query</parameter></methodparam>
|
||
|
</methodsynopsis>
|
||
|
<para>
|
||
|
<function>maxdb_stmt_prepare</function> prepares the SQL query pointed to by the
|
||
|
null-terminated string query. The statement resource has to be allocated by
|
||
|
<function>maxdb_stmt_init</function>.
|
||
|
The query must consist of a single SQL statement.
|
||
|
</para>
|
||
|
<note>
|
||
|
<para>
|
||
|
You should not add a terminating semicolon or <literal>\g</literal>
|
||
|
to the statement.
|
||
|
</para>
|
||
|
</note>
|
||
|
<para>
|
||
|
The parameter <parameter>query</parameter> can include one or more parameter markers
|
||
|
in the SQL statement by embedding question mark (<literal>?</literal>) characters
|
||
|
at the appropriate positions.
|
||
|
</para>
|
||
|
<note>
|
||
|
<para>
|
||
|
The markers are legal only in certain places in SQL statements.
|
||
|
For example, they are allowed in the VALUES() list of an INSERT statement
|
||
|
(to specify column values for a row), or in a comparison with a column in
|
||
|
a WHERE clause to specify a comparison value.
|
||
|
</para>
|
||
|
<para>
|
||
|
However, they are not allowed for identifiers (such as table or column names),
|
||
|
in the select list that names the columns to be returned by a SELECT statement),
|
||
|
or to specify both operands of a binary operator such as the <literal>=</literal>
|
||
|
equal sign. The latter restriction is necessary because it would be impossible
|
||
|
to determine the parameter type. In general, parameters are legal only in Data
|
||
|
Manipulation Languange (DML) statements, and not in Data Defination Language
|
||
|
(DDL) statements.
|
||
|
</para>
|
||
|
</note>
|
||
|
<para>
|
||
|
The parameter markers must be bound to application variables using
|
||
|
<function>maxdb_stmt_bind_param</function> and/or <function>maxdb_stmt_bind_result</function>
|
||
|
before executing the statement or fetching rows.
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
<refsect1>
|
||
|
&reftitle.returnvalues;
|
||
|
<para>
|
||
|
&return.success;
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
<refsect1>
|
||
|
&reftitle.seealso;
|
||
|
<para>
|
||
|
<function>maxdb_stmt_init</function>,
|
||
|
<function>maxdb_stmt_execute</function>,
|
||
|
<function>maxdb_stmt_fetch</function>,
|
||
|
<function>maxdb_stmt_bind_param</function>,
|
||
|
<function>maxdb_stmt_bind_result</function>,
|
||
|
<function>maxdb_stmt_close</function>
|
||
|
</para>
|
||
|
</refsect1>
|
||
|
<refsect1>
|
||
|
<title>Example</title>
|
||
|
<example>
|
||
|
<title>Procedural style</title>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?php
|
||
|
$link = maxdb_connect("localhost", "MONA", "RED");
|
||
|
|
||
|
/* check connection */
|
||
|
if (maxdb_connect_errno()) {
|
||
|
printf("Connect failed: %s\n", maxdb_connect_error());
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
$city = "Portland";
|
||
|
|
||
|
/* create a prepared statement */
|
||
|
$stmt = maxdb_stmt_init($link);
|
||
|
if (maxdb_stmt_prepare($stmt, "SELECT state FROM hotel.city WHERE name=?")) {
|
||
|
|
||
|
/* bind parameters for markers */
|
||
|
maxdb_stmt_bind_param($stmt, "s", $city);
|
||
|
|
||
|
/* execute query */
|
||
|
maxdb_stmt_execute($stmt);
|
||
|
|
||
|
/* bind result variables */
|
||
|
maxdb_stmt_bind_result($stmt, $district);
|
||
|
|
||
|
/* fetch value */
|
||
|
maxdb_stmt_fetch($stmt);
|
||
|
|
||
|
printf("%s is in district %s\n", $city, $district);
|
||
|
|
||
|
/* close statement */
|
||
|
maxdb_stmt_close($stmt);
|
||
|
}
|
||
|
|
||
|
/* close connection */
|
||
|
maxdb_close($link);
|
||
|
?>
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
<para>
|
||
|
The above examples would produce the following output:
|
||
|
</para>
|
||
|
<screen>
|
||
|
<![CDATA[
|
||
|
Portland is in district OR
|
||
|
]]>
|
||
|
</screen>
|
||
|
</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
|
||
|
-->
|