From 5f441df4b7434bf97d06f1ac30145cb19ab69632 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 23 Mar 2015 09:49:49 +0000 Subject: [PATCH] dblayer : add the connected tests before using the SQLITE PDO engine git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2051 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayer.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dblayer.php b/dblayer.php index 405a465..74279aa 100644 --- a/dblayer.php +++ b/dblayer.php @@ -102,18 +102,8 @@ class dblayer extends PDO switch ($driver[0]) { case "sqlite": - try - { - parent::__construct ($dsn, $username, $password, $driver_options); - parent::setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - catch (Exception $e) - { - throw new Exception ("PDO error : ".$e->getMessage(), 500); - } - // Look at the right to write in database and in the directory - $file = substr ($dsn, 7); + $file = substr ($dsn, 9); if (! is_writeable (dirname ($file))) throw new Exception (dgettext("domframework", "The directory for SQLite database is write protected"), @@ -125,6 +115,16 @@ class dblayer extends PDO if (function_exists ("posix_getuid") && fileowner ($file) === posix_getuid ()) chmod ($file, 0666); + try + { + parent::__construct ($dsn, $username, $password, $driver_options); + parent::setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (Exception $e) + { + throw new Exception ("PDO error : ".$e->getMessage(), 500); + } + // Force ForeignKeys support (disabled by default) $this->exec("PRAGMA foreign_keys = ON"); $this->sep = "`";