<!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 returns an SQLiteDatabase object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-exec.html">sqlite_exec</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-fetch-all.html">sqlite_fetch_all</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-factory" class="refentry"> <div class="refnamediv"> <h1 class="refname">sqlite_factory</h1> <p class="verinfo">(PHP 5 < 5.4.0)</p><p class="refpurpose"><span class="refname">sqlite_factory</span> — <span class="dc-title">Opens an SQLite database and returns an SQLiteDatabase object</span></p> </div> <div class="refsect1 description" id="refsect1-function.sqlite-factory-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type SQLiteDatabase">SQLiteDatabase</span></span> <span class="methodname"><strong>sqlite_factory</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"> <span class="function"><strong>sqlite_factory()</strong></span> behaves similarly to <span class="function"><a href="function.sqlite-open.html" class="function">sqlite_open()</a></span> in that it opens an SQLite database or attempts to create it if it does not exist. However, a <a href="ref.sqlite.html#sqlite.class.sqlitedatabase" class="link">SQLiteDatabase</a> object is returned rather than a resource. Please see the <span class="function"><a href="function.sqlite-open.html" class="function">sqlite_open()</a></span> reference page for further usage and caveats. </p> </div> <div class="refsect1 parameters" id="refsect1-function.sqlite-factory-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"> The filename of the SQLite database. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">mode</code></em></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 <em>0666</em> and this is the recommended value. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">error_message</code></em></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" id="refsect1-function.sqlite-factory-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an SQLiteDatabase object on success, <strong><code>NULL</code></strong> on error. </p> </div> <div class="refsect1 examples" id="refsect1-function.sqlite-factory-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2142"> <p><strong>Example #1 <span class="function"><strong>sqlite_factory()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$dbhandle </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_factory</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT user_id, username FROM users'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* functionally equivalent to: */<br /><br /></span><span style="color: #0000BB">$dbhandle </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLiteDatabase</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT user_id, username FROM users'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.sqlite-factory-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.sqlite-open.html" class="function" rel="rdfs-seeAlso">sqlite_open()</a> - Opens an SQLite database and create the database if it does not exist</span></li> <li class="member"> <span class="function"><a href="function.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> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-exec.html">sqlite_exec</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-fetch-all.html">sqlite_fetch_all</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>