Source of: /manual/en/function.sqlite-array-query.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sqlite.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.sqlite-array-query.php',
1 => 'sqlite_array_query',
),
'up' =>
array (
0 => 'ref.sqlite.php',
1 => 'SQLite Functions',
),
'prev' =>
array (
0 => 'ref.sqlite.php',
1 => 'SQLite Functions',
),
'next' =>
array (
0 => 'function.sqlite-busy-timeout.php',
1 => 'sqlite_busy_timeout',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.sqlite-array-query" class="refentry">
<div class="refnamediv">
<h1 class="refname">sqlite_array_query</h1>
<h1 class="refname">SQLiteDatabase->arrayQuery</h1>
<p class="verinfo">(PHP 5, PECL sqlite >= 1.0.0)</p><p class="refpurpose"><span class="refname">sqlite_array_query</span> -- <span class="refname">SQLiteDatabase->arrayQuery</span> — <span class="dc-title">Execute a query against a given database and returns an array</span></p>
</div>
<a name="function.sqlite-array-query.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><b>sqlite_array_query</b></span>
( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span>
, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt></span>
]] )</div>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><b>sqlite_array_query</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
, <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt></span>
]] )</div>
<p class="para rdfs-comment">Object oriented style (method):</p>
<div class="classsynopsis">
<div class="ooclass"><b class="classname">SQLiteDatabase</b></div>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><b>arrayQuery</b></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt></span>
]] )</div>
</div>
<p class="para">
<b>sqlite_array_query()</b> executes the given query and returns
an array of the entire result set. It is similar to calling
<a href="function.sqlite-query.php" class="function">sqlite_query()</a> and then <a href="function.sqlite-fetch-array.php" class="function">sqlite_fetch_array()</a>
for each row in the result set. <b>sqlite_array_query()</b> is
significantly faster than the aforementioned.
</p>
<div class="tip"><b class="tip">Tip</b>
<p class="para">
<b>sqlite_array_query()</b> is best suited to queries
returning 45 rows or less. If you have more data than that, it is
recommended that you write your scripts to use
<a href="function.sqlite-unbuffered-query.php" class="function">sqlite_unbuffered_query()</a> instead for more optimal
performance.
</p>
</div>
</div>
<a name="function.sqlite-array-query.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">query</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The query to be executed.
</p>
<p class="para">
Data inside the query should be <a href="function.sqlite-escape-string.php" class="link">properly escaped</a>.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">dbhandle</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The SQLite Database resource; returned from <a href="function.sqlite-open.php" class="function">sqlite_open()</a>
when used procedurally. This parameter is not required
when using the object-oriented method.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">result_type</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">The optional <i><tt class="parameter">result_type</tt></i>
parameter accepts a constant and determines how the returned array will be
indexed. Using <b><tt class="constant">SQLITE_ASSOC</tt></b> will return only associative
indices (named fields) while <b><tt class="constant">SQLITE_NUM</tt></b> will return
only numerical indices (ordinal field numbers). <b><tt class="constant">SQLITE_BOTH</tt></b>
will return both associative and numerical indices.
<b><tt class="constant">SQLITE_BOTH</tt></b> is the default for this function.</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">decode_binary</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">When the <i><tt class="parameter">decode_binary</tt></i>
parameter is set to <b><tt class="constant">TRUE</tt></b> (the default), PHP will decode the binary encoding
it applied to the data if it was encoded using the
<a href="function.sqlite-escape-string.php" class="function">sqlite_escape_string()</a>. You should normally leave this
value at its default, unless you are interoperating with databases created by
other sqlite capable applications.</p>
</dd>
</dl>
<p>
</p>
<blockquote><p><b class="note">Note</b>: <span class="simpara">Two alternative syntaxes are
supported for compatibility with other database extensions (such as MySQL).
The preferred form is the first, where the <i><tt class="parameter">dbhandle</tt></i>
parameter is the first parameter to the function.</span></p></blockquote>
</div>
<a name="function.sqlite-array-query.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns an array of the entire result set; <b><tt class="constant">FALSE</tt></b> otherwise.
</p>
<p class="para">The column names returned by
<b><tt class="constant">SQLITE_ASSOC</tt></b> and <b><tt class="constant">SQLITE_BOTH</tt></b> will be
case-folded according to the value of the
<a href="sqlite.configuration.php#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a> configuration
option.</p>
</div>
<a name="function.sqlite-array-query.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Procedural style</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$dbhandle </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_array_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT name, email FROM users LIMIT 25'</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br />foreach (</span><span style="color: #0000BB">$result </span><span style="color: #007700">as </span><span style="color: #0000BB">$entry</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'Name: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">] . </span><span style="color: #DD0000">' E-mail: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'email'</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 Object-oriented style</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$dbhandle </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLiteDatabase</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">arrayQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT name, email FROM users LIMIT 25'</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br />foreach (</span><span style="color: #0000BB">$result </span><span style="color: #007700">as </span><span style="color: #0000BB">$entry</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'Name: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">] . </span><span style="color: #DD0000">' E-mail: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'email'</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.sqlite-array-query.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.sqlite-query.php" class="function" rel="rdfs-seeAlso">sqlite_query()</a> - Executes a query against a given database and returns a result handle</li>
<li class="member"><a href="function.sqlite-fetch-array.php" class="function" rel="rdfs-seeAlso">sqlite_fetch_array()</a> - Fetches the next row from a result set as an array</li>
<li class="member"><a href="function.sqlite-fetch-string.php" class="function" rel="rdfs-seeAlso">sqlite_fetch_string()</a> - Alias of sqlite_fetch_single</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>