dblayer : Check if the database is connected before using it

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1985 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-02-02 13:49:33 +00:00
parent 5184788658
commit b4241e1f30

View File

@@ -167,7 +167,7 @@ class dblayer extends PDO
/** Return the connected database name from DSN used to connect */
public function databasename ()
{
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
$vals = explode (";", substr (strstr ($this->dsn, ":"), 1));
@@ -185,7 +185,7 @@ class dblayer extends PDO
/** Return all the tables available in the database */
public function listTables ()
{
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
switch ($this->getAttribute(PDO::ATTR_DRIVER_NAME))
@@ -515,7 +515,7 @@ class dblayer extends PDO
public function insert ($datas)
{
if ($this->debug) echo "== Entering insert\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
if ($this->unique === null)
@@ -605,7 +605,7 @@ class dblayer extends PDO
$whereOr=false)
{
if ($this->debug) echo "== Entering read\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
if ($select !== null && !is_array ($select))
@@ -721,7 +721,7 @@ class dblayer extends PDO
public function update ($updatekey, $datas)
{
if ($this->debug) echo "== Entering update\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
if (count ($this->fields) === 0)
@@ -806,7 +806,7 @@ class dblayer extends PDO
public function delete ($deletekey)
{
if ($this->debug) echo "== Entering delete\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"));
$req = "DELETE FROM $this->sep$this->tableprefix$this->table$this->sep ";
$req .= "WHERE $this->primary = :primary";
@@ -843,7 +843,7 @@ class dblayer extends PDO
public function dropTable ()
{
if ($this->debug) echo "== Entering dropTables\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"));
$sql = "DROP TABLE $this->sep$this->tableprefix$this->table$this->sep";
if ($this->debug)
@@ -870,7 +870,7 @@ class dblayer extends PDO
public function createTable ()
{
if ($this->debug) echo "== Entering createTable\n";
if ($this === null)
if ($this->sep === "")
throw new Exception (dgettext("domframework", "Database not connected"),
500);
if (count ($this->fields) === 0)