目录
SQLite3::open
SQLite3::open — Opens an SQLite database
打开一个SQLite数据库
说明
public SQLite3::open ( string $filename [, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE [, string $encryption_key = "" ]] ) : void
Opens an SQLite 3 Database. If the build includes encryption, then it will attempt to use the key.
打开一个SQLite数据库,如果建立需要引入加密,那么它将企图使用这个秘钥。
参数
filename 文件名|数据库名
Path to the SQLite database, or :memory: to use in-memory database.
通往这个SQLite数据库的路径,或者内存去使用在内存中的数据库。
flags 标识
Optional flags used to determine how to open the SQLite database. By default, open uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE.
可选择标识用于决定如何打开SQLite数据库。默认,用SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE打开。
SQLITE3_OPEN_READONLY: Open the database for reading only.
SQLITE3_OPEN_READONLY: 打开数据库仅提供读。
SQLITE3_OPEN_READWRITE: Open the database for reading and writing.
SQLITE3_OPEN_READWRITE: 打开数据库提供读和写。
SQLITE3_OPEN_CREATE: Create the database if it does not exist.
SQLITE3_OPEN_CREATE: 创建数据库,如果它不存在。
encryption_key 秘钥
An optional encryption key used when encrypting and decrypting an SQLite database. If the SQLite encryption module is not installed, this parameter will have no effect.
一个可选的加密秘钥,在SQLite数据库中使用加密和解密。如果这个SQLite加密模块没有安装,这个参数将没有效果。
返回值
没有返回值。
范例
Example #1 SQLite3::open() example
<?php
/**
* Simple example of extending the SQLite3 class and changing the __construct
* parameters, then using the open method to initialize the DB.
*/
class MyDB extends SQLite3
{
function __construct()
{
$this->open('mysqlitedb.db');
}
}
$db = new MyDB();
$db->exec('CREATE TABLE foo (bar STRING)');
$db->exec("INSERT INTO foo (bar) VALUES ('This is a test')");
$result = $db->query('SELECT bar FROM foo');
var_dump($result->fetchArray());
?>