uTools-Manuals/docs/php/sqlite_fetch_array.html
2019-04-28 19:00:34 +08:00

150 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>Fetches the next row from a result set as an array</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.sqlite-fetch-array" class="refentry">
<div class="refnamediv">
<h1 class="refname">sqlite_fetch_array</h1>
<h1 class="refname">SQLiteResult::fetch</h1>
<h1 class="refname">SQLiteUnbuffered::fetch</h1>
<p class="verinfo">(PHP 5 &lt; 5.4.0, PECL sqlite &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">sqlite_fetch_array</span> -- <span class="refname">SQLiteResult::fetch</span> -- <span class="refname">SQLiteUnbuffered::fetch</span> &mdash; <span class="dc-title">Fetches the next row from a result set as an array</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.sqlite-fetch-array-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>sqlite_fetch_array</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</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"> = <strong><code>TRUE</code></strong></span></span>
]] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">面向对象风格 (method):</p>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>SQLiteResult::fetch</strong></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"> = <strong><code>TRUE</code></strong></span></span>
]] ) : <span class="type">array</span></div>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>SQLiteUnbuffered::fetch</strong></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"> = <strong><code>TRUE</code></strong></span></span>
]] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
Fetches the next row from the given <code class="parameter">result</code> handle.
If there are no more rows, returns <strong><code>FALSE</code></strong>, otherwise returns an
associative array representing the row data.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.sqlite-fetch-array-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">result</code></dt>
<dd>
<p class="para">
The SQLite result resource. This parameter is not required when using
the object-oriented method.
</p>
</dd>
<dt>
<code class="parameter">result_type</code></dt>
<dd>
<p class="para">可选的 <code class="parameter">result_type</code>
参数接受常量,且决定返回的数组如何被索引。使用
<strong><code>SQLITE_ASSOC</code></strong> 会仅返回关联索引(已命名字段),而
<strong><code>SQLITE_NUM</code></strong> 会仅返回数值索引。<strong><code>SQLITE_BOTH</code></strong>
会同时返回关联和数值索引。<strong><code>SQLITE_BOTH</code></strong> 是此函数的默认值。</p>
</dd>
<dt>
<code class="parameter">decode_binary</code></dt>
<dd>
<p class="para">
<code class="parameter">decode_binary</code> 参数设置为 <strong><code>TRUE</code></strong>默认值PHP 会解码那些由
<span class="function"><a href="sqlite_escape_string.html" class="function">sqlite_escape_string()</a></span>
编码后的二进制数据。通常应保留此值为其默认值,除非要与其他使用 SQLlite 的应用程序建立的数据交互。</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.sqlite-fetch-array-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns an array of the next row from a result set; <strong><code>FALSE</code></strong> if the
next position is beyond the final row.
</p>
<p class="para">
<strong><code>SQLITE_ASSOC</code></strong><strong><code>SQLITE_BOTH</code></strong>
返回的列名会依照 <a href="sqlite.configuration.html#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a>
配置选项的值决定大小写。</p>
</div>
<div class="refsect1 examples" id="refsect1-function.sqlite-fetch-array-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2538">
<p><strong>Example #1 Procedural example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><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">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_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">);<br />while&nbsp;(</span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLITE_ASSOC</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>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-2539">
<p><strong>Example #2 Object-oriented example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><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 /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</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: #FF8000">//&nbsp;buffered&nbsp;result&nbsp;set<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">unbufferedQuery</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: #FF8000">//&nbsp;unbuffered&nbsp;result&nbsp;set<br /><br /></span><span style="color: #007700">while&nbsp;(</span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLITE_ASSOC</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>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.sqlite-fetch-array-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="sqlite_array_query.html" class="function" rel="rdfs-seeAlso">sqlite_array_query()</a> - Execute a query against a given database and returns an array</span></li>
<li class="member"><span class="function"><a href="sqlite_fetch_string.html" class="function" rel="rdfs-seeAlso">sqlite_fetch_string()</a> - 别名 sqlite_fetch_single</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>