diff --git a/dblayer.php b/dblayer.php index da88f83..df2f6aa 100644 --- a/dblayer.php +++ b/dblayer.php @@ -33,6 +33,11 @@ require_once ("domframework/verify.php"); /** Permit abstraction on the differents SQL databases available */ class dblayer extends PDO { + /** The table name to use */ + public $table = null; + /** The prefix text to prepend to table name (Should finish by _) + Just allow chars ! */ + public $prefix = ""; /** The fields with the definition of type, and special parameters */ public $fields = array (); /** The primary field */ @@ -276,7 +281,7 @@ class dblayer extends PDO $column), 405); } - $req = "INSERT INTO `".$this->table."` "; + $req = "INSERT INTO `".$this->prefix.$this->table."` "; $req .= "(".implode (",", array_keys ($datasOK)).")"; $req .= " VALUES "; $req .= "(:".implode (",:", array_keys ($datasOK)).")"; @@ -339,7 +344,7 @@ class dblayer extends PDO $req = "SELECT "; $req .= implode (",", $display); - $req .= " FROM `".$this->table."`"; + $req .= " FROM `".$this->prefix.$this->table."`"; if ($select !== null) { $req .= " WHERE "; @@ -499,7 +504,7 @@ class dblayer extends PDO } $datasOK[$this->primary] = $updatekey; - $req = "UPDATE `".$this->table."` SET "; + $req = "UPDATE `".$this->prefix.$this->table."` SET "; $i = 0; foreach ($datasOK as $key=>$val) { @@ -552,7 +557,7 @@ class dblayer extends PDO { if ($this->db === null) throw new Exception ("Database not connected"); - $req = "DELETE FROM `".$this->table."` "; + $req = "DELETE FROM `".$this->prefix.$this->table."` "; $req .= "WHERE $this->primary = :primary"; $st = $this->db->prepare ($req); if ($this->debug) echo "DEBUG : $req\n"; @@ -595,7 +600,7 @@ class dblayer extends PDO switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME)) { case "sqlite": - $sql = "CREATE TABLE `$this->table` (\n"; + $sql = "CREATE TABLE `$this->prefix.$this->table` (\n"; $i = 0; foreach ($this->fields as $field=>$params) { @@ -676,7 +681,7 @@ class dblayer extends PDO $sql .=")"; break; case "mysql": - $sql = "CREATE TABLE `$this->table` (\n"; + $sql = "CREATE TABLE `$this->prefix.$this->table` (\n"; $i = 0; foreach ($this->fields as $field=>$params) { @@ -755,7 +760,7 @@ class dblayer extends PDO $sql .=") ENGINE=InnoDB DEFAULT CHARSET=utf8;"; break; case "pgsql": - $sql = "CREATE TABLE \"$this->table\" (\n"; + $sql = "CREATE TABLE \"$this->prefix.$this->table\" (\n"; $i = 0; foreach ($this->fields as $field=>$params) {