sqlite_open
(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
sqlite_open — Opens an SQLite database and create the database if it does not exist
Description
$filename
[, int $mode
= 0666
[, string &$error_message
]] ) : resourceObject oriented style (constructor):
$filename
[, int $mode
= 0666
[, string &$error_message
]] )Opens an SQLite database or creates the database if it does not exist.
Parameters
-
filename
-
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.
-
mode
-
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 0666 and this is the recommended value.
-
error_message
-
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.
Examples
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);
}
?>
Notes
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.
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() - Opens a persistent handle to an SQLite database and create the database if it does not exist
- sqlite_close() - Closes an open SQLite database
- sqlite_factory() - Opens an SQLite database and returns an SQLiteDatabase object
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.sqlite-open.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.