Opening SQLite3 as READONLY with PDO?

0 votes
asked Aug 29, 2009 by karl-blessing

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?

2 Answers

0 votes
answered Aug 29, 2009 by volkerk

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.

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.

0 votes
answered Sep 15, 2017 by anthonyryan1

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

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter