Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening SQLite3 as READONLY with PDO?

Tags:

php

sqlite

pdo

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?

like image 241
Karl Blessing Avatar asked Aug 29 '09 20:08

Karl Blessing


Video Answer


1 Answers

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

The syntax is as follows:

$db = new PDO('sqlite:mysqlitedb.db', null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);

Upstream commit

like image 100
anthonyryan1 Avatar answered Nov 10 '22 01:11

anthonyryan1