uTools-Manuals/docs/php/sqlite_open.html
2019-04-08 23:22:26 +08:00

168 lines
8.7 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>Opens an SQLite database and create the database if it does not exist</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.sqlite-open" class="refentry">
<div class="refnamediv">
<h1 class="refname">sqlite_open</h1>
<p class="verinfo">(PHP 5 &lt; 5.4.0, PECL sqlite &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">sqlite_open</span> &mdash; <span class="dc-title">Opens an SQLite database and create the database if it does not exist</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.sqlite-open-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>sqlite_open</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = 0666</span></span>
[, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_message</code></span>
]] ) : <span class="type">resource</span></div>
<p class="para rdfs-comment">面向对象风格 (constructor):</p>
<div class="constructorsynopsis dc-description">
<span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>SQLiteDatabase::__construct</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = 0666</span></span>
[, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_message</code></span>
]] )</div>
<p class="para rdfs-comment">
Opens an SQLite database or creates the database if it does not exist.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.sqlite-open-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">filename</code></dt>
<dd>
<p class="para">
The filename of the SQLite database. If the file does not exist, SQLite
will attempt to create it. PHP must have write permissions to the file
if data is inserted, the database schema is modified or to create the
database if it does not exist.
</p>
</dd>
<dt>
<code class="parameter">mode</code></dt>
<dd>
<p class="para">
The mode of the file. Intended to be used to open the database in
read-only mode. Presently, this parameter is ignored by the sqlite
library. The default value for mode is the octal value
<em>0666</em> and this is the recommended value.
</p>
</dd>
<dt>
<code class="parameter">error_message</code></dt>
<dd>
<p class="para">
Passed by reference and is set to hold a descriptive error message
explaining why the database could not be opened if there was an error.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.sqlite-open-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns a resource (database handle) on success, <strong><code>FALSE</code></strong> on error.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.sqlite-open-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2545">
<p><strong>Example #1 <span class="function"><strong>sqlite_open()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0666</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sqliteerror</span><span style="color: #007700">))&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'CREATE&nbsp;TABLE&nbsp;foo&nbsp;(bar&nbsp;varchar(10))'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;foo&nbsp;VALUES&nbsp;('fnord')"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'select&nbsp;bar&nbsp;from&nbsp;foo'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">sqlite_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">));&nbsp;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #0000BB">$sqliteerror</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.sqlite-open-notes">
<h3 class="title">注释</h3>
<div class="tip"><strong class="tip">Tip</strong>
<p class="simpara">
On Unix platforms, SQLite is sensitive to scripts that use the fork() system call. If you
do have such a script, it is recommended that you close the handle prior
to forking and then re-open it in the child and/or parent.
For more information on this issue, see
<a href="http://sqlite.org/c_interface.html" class="link external">&raquo;&nbsp;The C language interface
to the SQLite library</a> in the section entitled
<em>Multi-Threading And SQLite</em>.
</p>
</div>
<div class="tip"><strong class="tip">Tip</strong>
<p class="simpara">
It is not recommended to work with SQLite databases mounted on NFS
partitions. Since NFS is notoriously bad when it comes to locking you
may find that you cannot even open the database at all, and if it
succeeds, the locking behaviour may be undefined.
</p>
</div>
<blockquote class="note"><p><strong class="note">Note</strong>:
<span class="simpara">
Starting with SQLite library version 2.8.2, you can specify
<em>:memory:</em> as the <code class="parameter">filename</code> to
create a database that lives only in the memory of the computer.
This is useful mostly for temporary processing, as the in-memory
database will be destroyed when the process ends. It can also be
useful when coupled with the <em>ATTACH DATABASE</em> SQL
statement to load other databases and move and query data between them.
</span>
</p></blockquote>
<blockquote class="note"><p><strong class="note">Note</strong>:
<span class="simpara">
SQLite is <a href="ini.sect.safe-mode.html#ini.safe-mode" class="link">安全模式</a> and open_basedir aware.
</span>
</p></blockquote>
</div>
<div class="refsect1 seealso" id="refsect1-function.sqlite-open-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="sqlite_popen.html" class="function" rel="rdfs-seeAlso">sqlite_popen()</a> - Opens a persistent handle to an SQLite database and create the database if it does not exist</span></li>
<li class="member"><span class="function"><a href="sqlite_close.html" class="function" rel="rdfs-seeAlso">sqlite_close()</a> - Closes an open SQLite database</span></li>
<li class="member"><span class="function"><a href="sqlite_factory.html" class="function" rel="rdfs-seeAlso">sqlite_factory()</a> - Opens an SQLite database and returns an SQLiteDatabase object</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>