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
说明
sqlite_open ( string $filename [, int $mode = 0666 [, string &$error_message ]] ) : resource
面向对象风格 (constructor):
final public SQLiteDatabase::__construct ( string $filename [, int $mode = 0666 [, string &$error_message ]] )
Opens an SQLite database or creates the database if it does not exist.
打开SQLite数据库或者创建数据库,如果它不存在。
参数
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.
这是文件名或者SQLite数据库。如果这个文件不存在,SQLIite将企图创建它。文件往这里插入,PHP必须有写权限,这个数据库模式计划修改或者创建数据库,如果它不存在。
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.
文件模式。要以只读方式打开数据库。目前,这个参数可以忽略,在这个sqlite库中。模式是八进制的值,默认值是0666,并且这个是推荐使用的值。
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.
通过参考和设置,去保留描述性错误信息解释,为什么这个数据库不能打开,如果有一个错误。
返回值
Returns a resource (database handle) on success, FALSE on error.
返回一个资源(数据库句柄)表示成功,false表示错误。
范例
<?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);
}
?>