sqlite_open

(PHP 5)

sqlite_open -- Opens a SQLite database. Will create the database if it does not exist

Description

resource sqlite_open ( string filename [, int mode [, string &error_message]])

Returns a resource (database handle) on success, FALSE on error.

The filename parameter is the name of the database. It can be a relative or absolute path to the file that sqlite will use to store your data. If the file does not exist, sqlite will attempt to create it. You MUST have write permissions to the file if you want to insert data or modify the database schema.

The mode parameter specifies the mode of the file and is 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 0666 and this is the recommended value to use if you need access to the errmessage parameter.

errmessage is 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.

Example 1. sqlite_open() example

<?php
if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) {
    
sqlite_query($db, 'CREATE TABLE foo (bar varchar(10))');
    
sqlite_query($db, "INSERT INTO foo VALUES ('fnord')");
    
$result = sqlite_query($db, 'select bar from foo');
    
var_dump(sqlite_fetch_array($result));
} else {
    die(
$sqliteerror);
}
?>

Tip: 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 The C language interface to the SQLite library in the section entitled Multi-Threading And SQLite.

Tip: 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.

Note: Starting with SQLite library version 2.8.2, you can specify :memory: as the filename 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 ATTACH DATABASE SQL statement to load other databases and move and query data between them.

Note: SQLite is safe mode and open_basedir aware.

See also sqlite_popen(), sqlite_close() and sqlite_query().


Sites of interest: Web Hosting : Reseller Hosting : Website Hosting : HTML Editor : Web Design Templates : Free Web Hosting : ASP code examples : PHP & MySQL Code Examples
  Copyright 2004 Evrsoft Developer Network. Privacy policy - Link to Us

Contact Evrsoft