<HTML ><HEAD ><TITLE >sesam_query</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="SESAM database functions" HREF="ref.sesam.html"><LINK REL="PREVIOUS" TITLE="sesam_num_fields" HREF="function.sesam-num-fields.html"><LINK REL="NEXT" TITLE="sesam_rollback" HREF="function.sesam-rollback.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.sesam-num-fields.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.sesam-rollback.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.sesam-query" ></A >sesam_query</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN83654" ></A ><P > (PHP 3 CVS only)</P >sesam_query -- Perform a SESAM SQL query and prepare the result</DIV ><DIV CLASS="refsect1" ><A NAME="AEN83657" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >sesam_query</B > ( string query [, bool scrollable])<BR ></BR ><P > Returns: A SESAM "result identifier" on success, or <TT CLASS="constant" ><B >FALSE</B ></TT > on error. </P ><P > A "result_id" resource is used by other functions to retrieve the query results. </P ><P > <B CLASS="function" >sesam_query()</B > 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 <A HREF="function.sesam-fetch-row.html" ><B CLASS="function" >sesam_fetch_row()</B ></A > or <A HREF="function.sesam-fetch-result.html" ><B CLASS="function" >sesam_fetch_result()</B ></A > 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 <TT CLASS="parameter" ><I >scrollable</I ></TT > parameter) cursor will be allocated. If <TT CLASS="parameter" ><I >scrollable</I ></TT > is omitted, the cursor will be sequential. </P ><P > 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: <TT CLASS="literal" >SESAM_SEEK_NEXT</TT >) and the scrolling offset which can either be set once by <A HREF="function.sesam-seek-row.html" ><B CLASS="function" >sesam_seek_row()</B ></A > or each time when fetching a row using <A HREF="function.sesam-fetch-row.html" ><B CLASS="function" >sesam_fetch_row()</B ></A >. </P ><P > For "immediate" statements, the number of affected rows is saved for retrieval by the <A HREF="function.sesam-affected-rows.html" ><B CLASS="function" >sesam_affected_rows()</B ></A > function. </P ><P > See also: <A HREF="function.sesam-fetch-row.html" ><B CLASS="function" >sesam_fetch_row()</B ></A > and <A HREF="function.sesam-fetch-result.html" ><B CLASS="function" >sesam_fetch_result()</B ></A >. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN83686" ></A ><P ><B >Example 1. Show all rows of the "phone" table as a html table </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?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); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.sesam-num-fields.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.sesam-rollback.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >sesam_num_fields</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sesam.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >sesam_rollback</TD ></TR ></TABLE ></DIV ></BODY ></HTML >