Opening SQLite3 as READONLY with PDO?

北慕城南 提交于 2020-01-11 08:12:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!