From e17392e46259e6f2e012017987cf7c31c171488f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 28 Oct 2018 19:56:27 +0100 Subject: abstract config NWY --- w/class/modeldb.php | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'w/class/modeldb.php') diff --git a/w/class/modeldb.php b/w/class/modeldb.php index 7814acd..346a275 100644 --- a/w/class/modeldb.php +++ b/w/class/modeldb.php @@ -1,14 +1,18 @@ setbdd(); - } + $this->setbdd(); + //self::setdb(); + } + public function setbdd() @@ -16,7 +20,35 @@ class Modeldb extends Model $caught = true; try { - $this->bdd = new PDO('mysql:host=' . $this->config->host() . ';dbname=' . $this->config->dbname() . ';charset=utf8', $this->config->user(), $this->config->password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); + $this->bdd = new PDO('mysql:host=' . Config::host() . ';dbname=' . Config::dbname() . ';charset=utf8', Config::user(), Config::password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); + //$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { + $caught = false; + echo '

Error 500, database offline

'; + if ($this->session() >= self::EDITOR) { + echo '

Error : ' . $e->getMessage() . '

'; + if ($this->session() == self::ADMIN) { + echo '

Go to the Admin Panel to edit your database credentials

'; + } else { + echo '

Logout and and come back with an admin password to edit the database connexions settings.

'; + } + } else { + echo '

Homepage for admin login (connect on the top right side)

'; + } + exit; + } + + return $caught; + + } + + + public static function setdb() + { + $caught = true; + + try { + self::$db = new PDO('mysql:host=' . Config::host() . ';dbname=' . Config::dbname() . ';charset=utf8', Config::user(), Config::password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); //$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $caught = false; @@ -40,8 +72,8 @@ class Modeldb extends Model public function settable(Config $config) { - if (!empty($config->arttable())) { - $this->arttable = $config->arttable(); + if (!empty(Config::arttable())) { + $this->arttable = Config::arttable(); } else { echo '

Table Error

'; @@ -87,7 +119,6 @@ class Modeldb extends Model - } public function tablelist($dbname) -- cgit v1.2.3