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

search for in the

sqlite_popen> <sqlite_num_rows
[edit] Last updated: Thu, 12 Jan 2012

view this page in

sqlite_open

(PHP 5, PECL sqlite >= 1.0.0)

sqlite_openOpens an SQLite database and create the database if it does not exist

Descrierea

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

Stil obiect-orientat (constructor):

__construct ( string $filename [, int $mode = 0666 [, string &$error_message ]] )

Opens an SQLite database or creates the database if it does not exist.

Parametri

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.

Valorile întoarse

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

Exemple

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);
}
?>

Note

Sfat

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.

Sfat

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.

Notă: 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.

Notă: SQLite is modul securizat and open_basedir aware.

Vedeți de asemenea

  • 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



sqlite_popen> <sqlite_num_rows
[edit] Last updated: Thu, 12 Jan 2012
 
add a note add a note User Contributed Notes sqlite_open
koalay at gmail dot com 05-Oct-2011 09:05
This function only support database of SQLite 2 or below. For SQLite 3, you must use PDO.
simplersolution at gmail dot com 06-Dec-2007 06:46
I found that both the file and the directory it is in have to be writeable by the web server, or an ambiguous "unable to open database file" error appears (pecl 1.0.3).  I pulled my hair out for ages before I realised that.
Phillip Berndt 02-Mar-2007 06:52
If you miss to set the permissions mentioned by ivoras Sqlite will drop an error message saying "Malformed database scheme", which is somehow misleading.

(I mentioned this as some [I did] might search php.net for this error message)
15-Nov-2006 02:45
the above example dows not! work since sqlite_query() does not accept one argument, but only 2.

so correct is:

<?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);
}
?>
ivoras at fer dot hr 26-May-2004 10:46
Since sqlite uses a journal to do updates and inserts (and creates it on the fly), you ALSO must have write permissions set for the web server to write in the same DIRECTORY as the database file.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites