Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5848

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Execute a query against a given database and returns an array</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-busy-timeout.html">sqlite_busy_timeout</a></div>
 <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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 &lt; 5.4.0, PECL sqlite &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">sqlite_array_query</span> -- <span class="refname">SQLiteDatabase::arrayQuery</span> &mdash; <span class="dc-title">Execute a query against a given database and returns an array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sqlite-array-query-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>sqlite_array_query</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dbhandle</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_type</code><span class="initializer"> = SQLITE_BOTH</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$decode_binary</code><span class="initializer"> = true</span></span>
  ]] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>sqlite_array_query</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dbhandle</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_type</code><span class="initializer"> = SQLITE_BOTH</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$decode_binary</code><span class="initializer"> = true</span></span>
  ]] )</div>

  <p class="para rdfs-comment">Object oriented style (method):</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>SQLiteDatabase::arrayQuery</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_type</code><span class="initializer"> = SQLITE_BOTH</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$decode_binary</code><span class="initializer"> = true</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>sqlite_array_query()</strong></span> executes the given query and returns
   an array of the entire result set.  It is similar to calling
    <span class="function"><a href="function.sqlite-query.html" class="function">sqlite_query()</a></span> and then  <span class="function"><a href="function.sqlite-fetch-array.html" class="function">sqlite_fetch_array()</a></span>
   for each row in the result set.   <span class="function"><strong>sqlite_array_query()</strong></span> is
   significantly faster than the aforementioned.
  </p>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
     <span class="function"><strong>sqlite_array_query()</strong></span> 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
     <span class="function"><a href="function.sqlite-unbuffered-query.html" class="function">sqlite_unbuffered_query()</a></span> instead for more optimal
    performance.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sqlite-array-query-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">query</code></em></span>
     <dd>

      <p class="para">
       The query to be executed.
      </p>
      <p class="para">
       Data inside the query should be <a href="function.sqlite-escape-string.html" class="link">properly escaped</a>.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">dbhandle</code></em></span>
     <dd>

      <p class="para">
       The SQLite Database resource; returned from  <span class="function"><a href="function.sqlite-open.html" class="function">sqlite_open()</a></span>
       when used procedurally.  This parameter is not required
       when using the object-oriented method.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">result_type</code></em></span>
     <dd>

      <p class="para">The optional <em><code class="parameter">result_type</code></em>
parameter accepts a constant and determines how the returned array will be
indexed. Using <strong><code>SQLITE_ASSOC</code></strong> will return only associative
indices (named fields) while <strong><code>SQLITE_NUM</code></strong> will return
only numerical indices (ordinal field numbers). <strong><code>SQLITE_BOTH</code></strong>
will return both associative and numerical indices.
<strong><code>SQLITE_BOTH</code></strong> is the default for this function.</p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">decode_binary</code></em></span>
     <dd>

      <p class="para">When the <em><code class="parameter">decode_binary</code></em>
parameter is set to <strong><code>TRUE</code></strong> (the default), PHP will decode the binary encoding
it applied to the data if it was encoded using the
 <span class="function"><a href="function.sqlite-escape-string.html" class="function">sqlite_escape_string()</a></span>.  You should normally leave this
value at its default, unless you are interoperating with databases created by
other sqlite capable applications.</p>
     </dd>

    </dt>

   </dl>

  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: <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 <em><code class="parameter">dbhandle</code></em>
parameter is the first parameter to the function.</span></p></blockquote>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sqlite-array-query-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an array of the entire result set; <strong><code>FALSE</code></strong> otherwise.
  </p>
  <p class="para">The column names returned by
<strong><code>SQLITE_ASSOC</code></strong> and <strong><code>SQLITE_BOTH</code></strong> will be
case-folded according to the value of the
<a href="sqlite.configuration.html#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a> configuration
option.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sqlite-array-query-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2130">
    <p><strong>Example #1 Procedural style</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbhandle&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_array_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;name,&nbsp;email&nbsp;FROM&nbsp;users&nbsp;LIMIT&nbsp;25'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Name:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;&nbsp;E-mail:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2131">
    <p><strong>Example #2 Object-oriented style</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbhandle&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">arrayQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT&nbsp;name,&nbsp;email&nbsp;FROM&nbsp;users&nbsp;LIMIT&nbsp;25'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLITE_ASSOC</span><span style="color: #007700">);<br />foreach&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Name:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">[</span><span style="color: #DD0000">'name'</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;&nbsp;E-mail:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</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">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sqlite-array-query-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.sqlite-query.html" class="function" rel="rdfs-seeAlso">sqlite_query()</a> - Executes a query against a given database and returns a result handle</span></li>
    <li class="member"> <span class="function"><a href="function.sqlite-fetch-array.html" class="function" rel="rdfs-seeAlso">sqlite_fetch_array()</a> - Fetches the next row from a result set as an array</span></li>
    <li class="member"> <span class="function"><a href="function.sqlite-fetch-string.html" class="function" rel="rdfs-seeAlso">sqlite_fetch_string()</a> - Alias of sqlite_fetch_single</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-busy-timeout.html">sqlite_busy_timeout</a></div>
 <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>