<!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</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.loadextension.html">SQLite3::loadExtension</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.prepare.html">SQLite3::prepare</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sqlite3.open" class="refentry"> <div class="refnamediv"> <h1 class="refname">SQLite3::open</h1> <p class="verinfo">(PHP 5 >= 5.3.0)</p><p class="refpurpose"><span class="refname">SQLite3::open</span> — <span class="dc-title">Opens an SQLite database</span></p> </div> <div class="refsect1 description" id="refsect1-sqlite3.open-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>SQLite3::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">$flags</code><span class="initializer"> = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE</span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encryption_key</code></span> ]] )</div> <p class="para rdfs-comment"> Opens an SQLite 3 Database. If the build includes encryption, then it will attempt to use the key. </p> </div> <div class="refsect1 parameters" id="refsect1-sqlite3.open-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> Path to the SQLite database, or <em>:memory:</em> to use in-memory database. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">flags</code></em></span> <dd> <p class="para"> Optional flags used to determine how to open the SQLite database. By default, open uses <em>SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE</em>. <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <em>SQLITE3_OPEN_READONLY</em>: Open the database for reading only. </p> </li> <li class="listitem"> <p class="para"> <em>SQLITE3_OPEN_READWRITE</em>: Open the database for reading and writing. </p> </li> <li class="listitem"> <p class="para"> <em>SQLITE3_OPEN_CREATE</em>: Create the database if it does not exist. </p> </li> </ul> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">encryption_key</code></em></span> <dd> <p class="para"> An optional encryption key used when encrypting and decrypting an SQLite database. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-sqlite3.open-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 examples" id="refsect1-sqlite3.open-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2161"> <p><strong>Example #1 <span class="function"><strong>SQLite3::open()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/**<br /> * Simple example of extending the SQLite3 class and changing the __construct<br /> * parameters, then using the open method to initialize the DB.<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">MyDB </span><span style="color: #007700">extends </span><span style="color: #0000BB">SQLite3<br /></span><span style="color: #007700">{<br /> function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br /> {<br /> </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb.db'</span><span style="color: #007700">);<br /> }<br />}<br /><br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">MyDB</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE TABLE foo (bar STRING)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO foo (bar) VALUES ('This is a test')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT bar FROM foo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-></span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3.loadextension.html">SQLite3::loadExtension</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3.prepare.html">SQLite3::prepare</a></div> <div class="up"><a href="class.sqlite3.html">SQLite3</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>