php-doc-en/reference/maxdb/functions/maxdb-prepare.xml
Philip Olson 04b11e621f Fixed spelling
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@329325 c90b9560-bf6c-de11-be94-00142212c4b1
2013-01-29 01:47:09 +00:00

198 lines
5.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.maxdb-prepare">
<refnamediv>
<refname>maxdb_prepare</refname>
<refname>maxdb::prepare</refname>
<refpurpose>Prepare an SQL statement for execution</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<para>&style.procedural;</para>
<methodsynopsis>
<type>resource</type><methodname>maxdb_prepare</methodname>
<methodparam><type>resource</type><parameter>link</parameter></methodparam>
<methodparam><type>string</type><parameter>query</parameter></methodparam>
</methodsynopsis>
<para>&style.oop;</para>
<methodsynopsis>
<type>maxdb_stmt</type><methodname>maxdb::prepare</methodname>
<methodparam><type>string</type><parameter>query</parameter></methodparam>
</methodsynopsis>
<para>
<function>maxdb_prepare</function> prepares the SQL query pointed to by the
null-terminated string query, and returns a statement handle to be used for
further operations on the statement. 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 role="returnvalues">
&reftitle.returnvalues;
<para>
<function>maxdb_prepare</function> returns a statement resource or &false; if an error occurred.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>&style.oop;</title>
<programlisting role="php">
<![CDATA[
<?php
$maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
$city = "Rosemont";
/* create a prepared statement */
if ($stmt = $maxdb->prepare("SELECT state FROM hotel.city WHERE name=?")) {
/* bind parameters for markers */
$stmt->bind_param("s", $city);
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($district);
/* fetch value */
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);
/* close statement */
$stmt->close();
}
/* close connection */
$maxdb->close();
?>
]]>
</programlisting>
</example>
<example>
<title>&style.procedural;</title>
<programlisting role="php">
<![CDATA[
<?php
$link = maxdb_connect("localhost", "MONA", "RED", "DEMODB");
/* check connection */
if (maxdb_connect_errno()) {
printf("Connect failed: %s\n", maxdb_connect_error());
exit();
}
$city = "Rosemont";
/* create a prepared statement */
if ($stmt = maxdb_prepare($link, "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>
&example.outputs.similar;
<screen>
<![CDATA[
Rosemont is in district IL
]]>
</screen>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>maxdb_stmt_execute</function></member>
<member><function>maxdb_stmt_fetch</function></member>
<member><function>maxdb_stmt_bind_param</function></member>
<member><function>maxdb_stmt_bind_result</function></member>
<member><function>maxdb_stmt_close</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
-->