downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.sqlite-open.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.sqlite.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.sqlite-open.php',
   
1 => 'sqlite_open',
  ),
 
'up' =>
  array (
   
0 => 'ref.sqlite.php',
   
1 => 'SQLite Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.sqlite-num-rows.php',
   
1 => 'sqlite_num_rows',
  ),
 
'next' =>
  array (
   
0 => 'function.sqlite-popen.php',
   
1 => 'sqlite_popen',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.sqlite-open" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlite_open</h1>
  <p class="verinfo">(PHP 5, PECL sqlite &gt;= 1.0.0)</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>

 <a name="function.sqlite-open.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><b>sqlite_open</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 class="initializer"> = 0666</span></span>
   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&amp;$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>__construct</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 class="initializer"> = 0666</span></span>
    [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&amp;$error_message</tt></span>
   ]] )</div>

  </div>
  <p class="para">
   Opens a SQLite database or creates the database if it does not exist.
  </p>
 </div>


 <a name="function.sqlite-open.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">filename</tt></i>
</span>

     </dt><dd class="listitem">

      <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 class="varlistentry">

     <span class="term"><i><tt class="parameter">mode</tt></i>
</span>

     </dt><dd class="listitem">

      <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 class="varlistentry">

     <span class="term"><i><tt class="parameter">error_message</tt></i>
</span>

     </dt><dd class="listitem">

      <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>
  </p>
 </div>


 <a name="function.sqlite-open.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a resource (database handle) on success, <b><tt class="constant">FALSE</tt></b> on error.
  </p>
 </div>


 <a name="function.sqlite-open.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>sqlite_open()</b> example</b></p>
    <div class="example-contents programlisting">
<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>
  </p>
 </div>


 <a name="function.sqlite-open.notes"></a><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="ini.sect.safe-mode.php#ini.safe-mode" class="link">safe mode</a> and open_basedir aware.
   </span>
  </p></blockquote>
 </div>

 
 <a name="function.sqlite-open.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.sqlite-popen.php" 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</li>
    <li class="member"><a href="function.sqlite-close.php" class="function" rel="rdfs-seeAlso">sqlite_close()</a> - Closes an open SQLite database</li>
    <li class="member"><a href="function.sqlite-factory.php" class="function" rel="rdfs-seeAlso">sqlite_factory()</a> - Opens a SQLite database and returns a SQLiteDatabase object</li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites