mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
203 lines
8.5 KiB
HTML
203 lines
8.5 KiB
HTML
<!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>Executes a query against a given database and returns a result handle</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.sqlite-query" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">sqlite_query</h1>
|
|
<h1 class="refname">SQLiteDatabase::query</h1>
|
|
<p class="verinfo">(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)</p><p class="refpurpose"><span class="refname">sqlite_query</span> -- <span class="refname">SQLiteDatabase::query</span> — <span class="dc-title">Executes a query against a given database and returns a result handle</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.sqlite-query-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlite_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">string</span> <code class="parameter reference">&$error_msg</code></span>
|
|
]] ) : <span class="type">resource</span></div>
|
|
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlite_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">string</span> <code class="parameter reference">&$error_msg</code></span>
|
|
]] ) : <span class="type">resource</span></div>
|
|
|
|
<p class="para rdfs-comment">面向对象风格 (method):</p>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="modifier">public</span> <span class="methodname"><strong>SQLiteDatabase::query</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">string</span> <code class="parameter reference">&$error_msg</code></span>
|
|
]] ) : <span class="type"><span class="type SQLiteResult">SQLiteResult</span></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Executes an SQL statement given by the <code class="parameter">query</code> against
|
|
a given database handle.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.sqlite-query-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">dbhandle</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The SQLite Database resource; returned from
|
|
<span class="function"><a href="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>
|
|
<code class="parameter">query</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The query to be executed.
|
|
</p>
|
|
<p class="para">
|
|
Data inside the query should be <a href="sqlite_escape_string.html" class="link">properly escaped</a>.
|
|
</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">error_msg</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The specified variable will be filled if an error occurs. This is
|
|
specially important because SQL syntax errors can't be fetched using
|
|
the <span class="function"><a href="sqlite_last_error.html" class="function">sqlite_last_error()</a></span> function.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">为兼容其他数据库扩展(比如 MySQL),支持两种可替代的语法。推荐第一种格式,函数的第一个参数是<code class="parameter">dbhandle</code>。</span></p></blockquote>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.sqlite-query-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
This function will return a result handle 或者在失败时返回 <strong><code>FALSE</code></strong>.
|
|
For queries that return rows, the result handle can then be used with
|
|
functions such as <span class="function"><a href="sqlite_fetch_array.html" class="function">sqlite_fetch_array()</a></span> and
|
|
<span class="function"><a href="sqlite_seek.html" class="function">sqlite_seek()</a></span>.
|
|
</p>
|
|
<p class="para">
|
|
Regardless of the query type, this function will return <strong><code>FALSE</code></strong> if the
|
|
query failed.
|
|
</p>
|
|
<p class="para">
|
|
<span class="function"><strong>sqlite_query()</strong></span> returns a buffered, seekable result
|
|
handle. This is useful for reasonably small queries where you need to
|
|
be able to randomly access the rows. Buffered result handles will
|
|
allocate memory to hold the entire result and will not return until it
|
|
has been fetched. If you only need sequential access to the data, it is
|
|
recommended that you use the much higher performance
|
|
<span class="function"><a href="sqlite_unbuffered_query.html" class="function">sqlite_unbuffered_query()</a></span> instead.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.sqlite-query-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<p class="para">
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>5.1.0</td>
|
|
<td>
|
|
Added the <code class="parameter">error_msg</code> parameter
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.sqlite-query-notes">
|
|
<h3 class="title">注释</h3>
|
|
<div class="warning"><strong class="warning">Warning</strong>
|
|
<p class="simpara">
|
|
SQLite <em class="emphasis">will</em> execute multiple queries separated by
|
|
semicolons, so you can use it to execute a batch of SQL that you have
|
|
loaded from a file or have embedded in a script. However, this works only
|
|
when the result of the function is not used - if it is used,
|
|
only the first SQL statement would be executed. Function
|
|
<span class="function"><a href="sqlite_exec.html" class="function">sqlite_exec()</a></span> will always execute multiple SQL
|
|
statements.
|
|
</p>
|
|
<p class="simpara">
|
|
When executing multiple queries, the return value of this function
|
|
will be <strong><code>FALSE</code></strong> if there was an error, but undefined otherwise (it might
|
|
be <strong><code>TRUE</code></strong> for success or it might return a result handle).
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.sqlite-query-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="sqlite_unbuffered_query.html" class="function" rel="rdfs-seeAlso">sqlite_unbuffered_query()</a> - Execute a query that does not prefetch and buffer all data</span></li>
|
|
<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>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |