note 128530 added to pdo.construct

From: Date: Fri, 12 May 2023 12:19:40 +0000
Subject: note 128530 added to pdo.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-220485@lists.php.net to get a copy of this message
SQLite3: by default, the database file is created on opening if it does not exist (PDO::SQLITE_OPEN_CREATE). <?php $dsn = 'sqlite:D:\Databases\non_existing.db'; // file does not exist try { $dbh = new PDO($dsn); } catch(PDOException $e) { print $e->getMessage(); } ?> No Exception is thrown, instead file "non_existing.db" will be created. To avoid this, use: <?php $dsn = 'sqlite:D:\Databases\non_existing.db'; $options = [ PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READWRITE, ]; try { $dbh = new PDO('sqlite:D:\Databases\non_existing.db', null, null, $options); } catch(PDOException $e) { print $e->getMessage(); } ?> This will ouput: SQLSTATE[HY000] [14] unable to open database file If you want to open the database read-only, use PDO::SQLITE_OPEN_READONLY. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 2001:4bb8:114:3e20:64fe:80f6:3e56:68ff) ---- Manual Page -- https://php.net/manual/en/pdo.construct.php Edit -- https://main.php.net/note/edit/128530 Del: integrated -- https://main.php.net/note/delete/128530/integrated Del: useless -- https://main.php.net/note/delete/128530/useless Del: bad code -- https://main.php.net/note/delete/128530/bad+code Del: spam -- https://main.php.net/note/delete/128530/spam Del: non-english -- https://main.php.net/note/delete/128530/non-english Del: in docs -- https://main.php.net/note/delete/128530/in+docs Del: other reasons-- https://main.php.net/note/delete/128530 Reject -- https://main.php.net/note/reject/128530 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220485) next »