implementation sgbd herite de mw_sgbd
[mtweb] / mw / app / data / impl / mw_pdo_mysql.php
index e8ae3ee..a230626 100644 (file)
@@ -1,38 +1,28 @@
 <?php
 
-  class mw_pdo_mysql{
-
-    public $link;
-    public $host;
-    public $base;
-    public $user;
-    public $password;
-    public $EXTENTION_OK;
-
-    public function __construct($params = array()){
-      $this->host = isset($params["host"]) ? $params["host"] : "localhost";
-      $this->base = isset($params["base"]) ? $params["base"] : "mtweb";
-      $this->user = isset($params["user"]) ? $params["user"] : "";
-      $this->password = isset($params["password"]) ? $params["password"] : "";
-      $this->EXTENTION_OK = (extension_loaded("pdo") && extension_loaded("pdo_mysql"));
+  class mw_pdo_mysql extends mw_sgbd{
+
+    public function name(){
+      return "PDO MySql";
     }
 
-    public function get_link(){
-      return $this->link;
+    public function default_params(){
+      return array(
+        "host" => "localhost",
+        "base" => "mtweb",
+        "user" => "",
+        "password" => ""
+      );
     }
 
-    public function extention_ok(&$env){
-      return $this->EXTENTION_OK;
+    public function validate_extention(){
+      return extension_loaded("pdo") && extension_loaded("pdo_mysql");
     }
 
     public function authentication_required(){
       return true;
     }
 
-    public function sgbd_name(){
-      return "PDO MySql";
-    }
-
     public function connect($host, $base, $user, $password){
       try{
         $this->link = new PDO("mysql:host=".$host.";dbname=".$base, $user, $password);
@@ -51,6 +41,7 @@
     }
 
     public function desc_table($table_name){
+      $table_name = $this->replace_prefixes($table_name);
       $sql = "SELECT * from information_schema.columns where table_name='".$table_name."'";
       $rst = $this->query($sql);
       $desc = array(
@@ -74,6 +65,7 @@
     }
 
     public function table_exists($table_name){
+      $table_name = $this->replace_prefixes($table_name);
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       $EXISTS = false;
       try{
@@ -93,6 +85,7 @@
     }
 
     public function field_exists($table_name, $field_name){
+      $table_name = $this->replace_prefixes($table_name);
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       if(!($desc = $this->desc_table($table_name))){
         throw new Exception($this->exception_out("Impossible de lire la description de la table"));
       return $EXISTS;
     }
 
-    public function query($query_string){\r
+    public function query($query_string){
+      $query_string = $this->replace_prefixes($query_string);\r
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       if(!($result = $this->link->query($query_string))){
         throw new Exception($this->exception_out("Syntaxe invalide dans une requete"));