问题
The SQLite3 Class has an option like this.
$db = new SQLite3('mysqlitedb.db', SQLITE3_OPEN_READONLY);
In PDO you would simply open with:
$db = new PDO('sqlite:mysqlitedb.db');
My question is however, is there a way to open a database with PDO, in READONLY mode?
回答1:
This will become possible with the release of PHP 7.3 (estimated for release in late 2018).
Thes syntax is as follows:
$db = new PDO('sqlite:mysqlitedb.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
Upstream commit
回答2:
I don't think that's possible with pdo (yet?).
The pdo_sqlite driver of php 5.3 uses sqlite3_open() in pdo_sqlite_handle_factory()
but you need sqlite3_open_v2() to pass the read only flag.
edit:
But a patch would be fairly easy. Take a look at pdo_mysql_handle_factory()
in ext/pdo_mysql/mysql_driver.c and how it uses struct pdo_data_src_parser vars[]
to parse the dns string.
来源:https://stackoverflow.com/questions/1352270/opening-sqlite3-as-readonly-with-pdo