1--TEST--
2PDO_sqlite: Testing open flags
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7
8$filename = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db";
9
10// Default open flag is read-write|create
11$db = new PDO('sqlite:' . $filename, null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
12
13var_dump($db->exec('CREATE TABLE test_sqlite_open_flags (id INT);'));
14
15$db = new PDO('sqlite:' . $filename, null, null, [PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
16
17var_dump($db->exec('CREATE TABLE test_sqlite_open_flags_2 (id INT);'));
18?>
19--CLEAN--
20<?php
21$filename = __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_open_flags.db";
22if (file_exists($filename)) {
23    unlink($filename);
24}
25?>
26--EXPECTF--
27int(0)
28
29Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s
30Stack trace:
31%s
32#1 {main}
33  thrown in %s
34