1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.6 $ -->
<!-- splitted from ./en/functions/sesam.xml, last change in rev 1.1 -->
<refentry id="function.sesam-query">
<refnamediv>
<refname>sesam_query</refname>
<refpurpose>Perform a SESAM SQL query and prepare the result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>sesam_query</methodname>
<methodparam><type>string</type><parameter>query</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>scrollable</parameter></methodparam>
</methodsynopsis>
<para>
Returns: A SESAM "result identifier" on success, or
&false; on error.
</para>
<para>
A "result_id" resource is used by other functions to retrieve the
query results.
</para>
<para>
<function>sesam_query</function> sends a query to the currently
active database on the server. It can execute both "immediate"
SQL statements and "select type" queries. If an "immediate"
statement is executed, then no cursor is allocated, and any
subsequent <function>sesam_fetch_row</function> or
<function>sesam_fetch_result</function> call will return an empty
result (zero columns, indicating end-of-result). For "select
type" statements, a result descriptor and a (scrollable or
sequential, depending on the optional boolean
<parameter>scrollable</parameter> parameter) cursor will be
allocated. If <parameter>scrollable</parameter> is omitted, the
cursor will be sequential.
</para>
<para>
When using "scrollable" cursors, the cursor can be freely
positioned on the result set. For each "scrollable" query, there
are global default values for the scrolling type (initialized to:
<literal>SESAM_SEEK_NEXT</literal>) and the scrolling offset
which can either be set once by
<function>sesam_seek_row</function> or each time when fetching a
row using <function>sesam_fetch_row</function>.
</para>
<para>
For "immediate" statements, the number of affected rows is saved
for retrieval by the <function>sesam_affected_rows</function>
function.
</para>
<para>
See also: <function>sesam_fetch_row</function> and
<function>sesam_fetch_result</function>.
<example>
<title>
Show all rows of the "phone" table as a HTML table
</title>
<programlisting role="php">
<![CDATA[
<?php
if (!sesam_connect("phonedb", "demo", "otto"))
die("cannot connect");
$result = sesam_query("select * from phone");
if (!$result) {
$err = sesam_diagnostic();
die ($err["errmsg"]);
}
echo "<table border>\n";
// Add title header with column names above the result:
if ($cols = sesam_field_array($result)) {
echo "<tr><th colspan=" . $cols["count"] . ">Result:</th></tr>\n";
echo "<tr>\n";
for ($col = 0; $col < $cols["count"]; ++$col) {
$colattr = $cols[$col];
/* Span the table head over SESAM's "Multiple Fields": */
if ($colattr["count"] > 1) {
echo "<th colspan=\"" . $colattr["count"] . "\">" . $colattr["name"] .
"(1.." . $colattr["count"] . ")</th>\n";
$col += $colattr["count"] - 1;
} else
echo "<th>" . $colattr["name"] . "</th>\n";
}
echo "</tr>\n";
}
do {
// Fetch the result in chunks of 100 rows max.
$ok = sesam_fetch_result($result, 100);
for ($row=0; $row < $ok["rows"]; ++$row) {
echo " <tr>\n";
for ($col = 0; $col < $ok["cols"]; ++$col) {
if (isset($ok[$col][$row])) {
echo "<td>" . $ok[$col][$row] . "</td>\n";
} else {
echo "<td>-empty-</td>\n";
}
}
echo "</tr>\n";
}
} while ($ok["truncated"]); // while there may be more data
echo "</table>\n";
// free result id
sesam_free_result($result);
?>
]]>
</programlisting>
</example>
</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
-->
|