使用PDO将SQLite3打开为READONLY?

时间:2022-10-11 05:36:34

The SQLite3 Class has an option like this.

SQLite3类有这样的选项。

$db = new SQLite3('mysqlitedb.db', SQLITE3_OPEN_READONLY);

In PDO you would simply open with:

在PDO中,您只需打开:

$db = new PDO('sqlite:mysqlitedb.db');

My question is however, is there a way to open a database with PDO, in READONLY mode?

但问题是,有没有办法在READONLY模式下用PDO打开数据库?

2 个解决方案

#1


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.

我觉得pdo不可能(但是?)。 php 5.3的pdo_sqlite驱动程序在pdo_sqlite_handle_factory()中使用sqlite3_open(),但是你需要sqlite3_open_v2()来传递只读标志。

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.

编辑:但补丁相当容易。看看ext / pdo_mysql / mysql_driver.c中的pdo_mysql_handle_factory()以及它如何使用struct pdo_data_src_parser vars []来解析dns字符串。

#2


2  

This will become possible with the release of PHP 7.3 (estimated for release in late 2018).

随着PHP 7.3的发布(预计将于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

上游提交

#1


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.

我觉得pdo不可能(但是?)。 php 5.3的pdo_sqlite驱动程序在pdo_sqlite_handle_factory()中使用sqlite3_open(),但是你需要sqlite3_open_v2()来传递只读标志。

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.

编辑:但补丁相当容易。看看ext / pdo_mysql / mysql_driver.c中的pdo_mysql_handle_factory()以及它如何使用struct pdo_data_src_parser vars []来解析dns字符串。

#2


2  

This will become possible with the release of PHP 7.3 (estimated for release in late 2018).

随着PHP 7.3的发布(预计将于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

上游提交