<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
  <refentry id="function.maxdb-query">
   <refnamediv>
    <refname>maxdb_query</refname>
    <refname>maxdb->query</refname>
    <refpurpose>Performs a query on the database</refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
    <para>Procedural style:</para>
    <methodsynopsis>
     <type>mixed</type><methodname>maxdb_query</methodname>
     <methodparam><type>resource</type><parameter>link</parameter></methodparam>
     <methodparam><type>string</type><parameter>query</parameter></methodparam>
     <methodparam choice='opt'><type>int</type><parameter>resultmode</parameter></methodparam>
    </methodsynopsis>
    <para>Object oriented style (method):</para>
    <classsynopsis>
     <ooclass><classname>maxdb</classname></ooclass>
     <methodsynopsis>
      <type>mixed</type>
      <methodname>query</methodname>
      <methodparam><type>string</type><parameter>query</parameter></methodparam>
     </methodsynopsis>
    </classsynopsis>
    <para>
     The <function>maxdb_query</function> function is used to simplify the
     act of performing a query against the database represented by the
     <parameter>link</parameter> parameter. 
    </para>
   </refsect1>
   <refsect1>
    <title>Return values</title>
    <para>
     &return.success; For <literal>SELECT, SHOW, DESCRIBE</literal> or
     <literal>EXPLAIN</literal> <function>maxdb_query</function> will return
     a result resource.
    </para>
   </refsect1>
   <refsect1>
    <title>See also</title>
    <para>
     <function>maxdb_real_query</function>,
     <function>maxdb_multi_query</function>,
     <function>maxdb_free_result</function>
    </para>
   </refsect1>
   <refsect1>
    <title>Example</title>
    <example>
     <title>Object oriented style</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();
}

/* Create table doesn't return a resultset */
if ($maxdb->query("CREATE TABLE temp.mycity LIKE hotel.city") === TRUE) {
   printf("Table mycity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = $maxdb->query("SELECT name FROM hotel.city")) {
   printf("Select returned %d rows.\n", $result->num_rows);

   /* free result set */
   $result->close();
}

/* If we have to retrieve large amount of data we use MAXDB_USE_RESULT */
if ($result = $maxdb->query("SELECT * FROM hotel.city", MAXDB_USE_RESULT)) {
   $result->close();
}

$maxdb->close();
?>
]]>
    </programlisting>
    </example>
    <example>
     <title>Procedural style</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();
}

/* Create table doesn't return a resultset */
if (maxdb_query($link, "CREATE TABLE temp.mycity LIKE hotel.city") === TRUE) {
   printf("Table mycity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = maxdb_query($link, "SELECT name FROM hotel.city")) {
   printf("Select returned %d rows.\n", maxdb_num_rows($result));

   /* free result set */
   maxdb_free_result($result);
}

/* If we have to retrieve large amount of data we use MAXDB_USE_RESULT */
if ($result = maxdb_query($link, "SELECT * FROM hotel.city", MAXDB_USE_RESULT)) {
   maxdb_free_result($result);
}

maxdb_close($link);
?>
]]>
     </programlisting>
    </example>
    <para>
     The above examples would produce the following output:
    </para>
    <screen>
<![CDATA[
Table mycity successfully created.
Select returned 25 rows.
]]>
    </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
-->