mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
191 lines
9.9 KiB
HTML
191 lines
9.9 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 result-less query against a given database</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.sqlite-exec" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">sqlite_exec</h1>
|
|
<h1 class="refname">SQLiteDatabase::exec</h1>
|
|
<p class="verinfo">(PHP 5 < 5.4.0, PECL sqlite >= 1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_exec</span> -- <span class="refname">SQLiteDatabase::exec</span> — <span class="dc-title">Executes a result-less query against a given database</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.sqlite-exec-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlite_exec</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">string</span> <code class="parameter reference">&$error_msg</code></span>
|
|
] ) : <span class="type">bool</span></div>
|
|
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>sqlite_exec</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="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">面向对象风格 (method):</p>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="modifier">public</span> <span class="methodname"><strong>SQLiteDatabase::queryExec</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_msg</code></span>
|
|
] ) : <span class="type">bool</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Executes an SQL statement given by the <code class="parameter">query</code> against
|
|
a given database handle (specified by the <code class="parameter">dbhandle</code>
|
|
parameter).
|
|
</p>
|
|
<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.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.sqlite-exec-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">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-exec-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
This function will return a boolean result; <strong><code>TRUE</code></strong> for success or <strong><code>FALSE</code></strong> for failure.
|
|
If you need to run a query that returns rows, see <span class="function"><a href="sqlite_query.html" class="function">sqlite_query()</a></span>.
|
|
</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 changelog" id="refsect1-function.sqlite-exec-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 examples" id="refsect1-function.sqlite-exec-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2533">
|
|
<p><strong>Example #1 Procedural example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><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">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">, </span><span style="color: #DD0000">"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'"</span><span style="color: #007700">, </span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$query</span><span style="color: #007700">) {<br /> exit(</span><span style="color: #DD0000">"Error in query: '</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />} else {<br /> echo </span><span style="color: #DD0000">'Number of rows modified: '</span><span style="color: #007700">, </span><span style="color: #0000BB">sqlite_changes</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
<p class="para">
|
|
<div class="example" id="example-2534">
|
|
<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"><?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">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">queryExec</span><span style="color: #007700">(</span><span style="color: #DD0000">"UPDATE users SET email='jDoe@example.com' WHERE username='jDoe'"</span><span style="color: #007700">, </span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$query</span><span style="color: #007700">) {<br /> exit(</span><span style="color: #DD0000">"Error in query: '</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />} else {<br /> echo </span><span style="color: #DD0000">'Number of rows modified: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">changes</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.sqlite-exec-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="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="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> |