function.sqlite-open.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 188 行

HTML
188
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Opens a SQLite database and create the database if it does not exist</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-num-rows.html">sqlite_num_rows</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-popen.html">sqlite_popen</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-open" class="refentry"> <div class="refnamediv">  <h1 class="refname">sqlite_open</h1>  <p class="verinfo">(PHP 5, PECL sqlite:1.0-1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_open</span> &mdash; <span class="dc-title">Opens a SQLite database and create the database if it does not exist</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">resource</span> <span class="methodname"><b><b>sqlite_open</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$filename</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$mode</tt></span>   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_message</tt></span>  ]] )</div>  <p class="para rdfs-comment">Object oriented style (constructor):</p>  <div class="classsynopsis">   <div class="ooclass"><b class="classname">SQLiteDatabase</b></div>   <div class="constructorsynopsis dc-description">     <span class="methodname"><b><b>__construct</b></b></span>     ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$filename</tt></span>    [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$mode</tt></span>    [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_message</tt></span>   ]] )</div>  </div>  <p class="para">   Opens a SQLite database or creates the database if it does not exist.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">filename</tt></i></span>     <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>    <dt>     <span class="term"><i><tt class="parameter">mode</tt></i></span>     <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       <i>0666</i> and this is the recommended value.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">error_message</tt></i></span>     <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>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns a resource (database handle) on success, <b><tt>FALSE</tt></b> on error.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>sqlite_open()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><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></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <div class="tip"><b class="tip">Tip</b>   <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; The C language interface    to the SQLite library</a> in the section entitled    <i>Multi-Threading And SQLite</i>.    </p>  </div>  <div class="tip"><b class="tip">Tip</b>   <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><p><b class="note">Note</b>:    <span class="simpara">    Starting with SQLite library version 2.8.2, you can specify    <i>:memory:</i> as the <i><tt class="parameter">filename</tt></i> 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 <i>ATTACH DATABASE</i> SQL    statement to load other databases and move and query data between them.   </span>  </p></blockquote>  <blockquote><p><b class="note">Note</b>:    <span class="simpara">    SQLite is <a href="features.safe-mode.html#ini.safe-mode" class="link">safe mode</a> and open_basedir aware.   </span>  </p></blockquote> </div>  <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.sqlite-popen.html" class="function" rel="rdfs-seeAlso">sqlite_popen()</a></li>    <li class="member"><a href="function.sqlite-close.html" class="function" rel="rdfs-seeAlso">sqlite_close()</a></li>    <li class="member"><a href="function.sqlite-factory.html" class="function" rel="rdfs-seeAlso">sqlite_factory()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-num-rows.html">sqlite_num_rows</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-popen.html">sqlite_popen</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>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?