implementation sgbd herite de mw_sgbd
[mtweb] / mw / app / data / impl / mw_mysql.php
index 8a58384..5128c04 100644 (file)
@@ -1,32 +1,26 @@
 <?php
 
-  class mw_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 = function_exists("mysql_connect");
+  class mw_mysql extends mw_sgbd{
+
+    public function name(){
+      return "MySql";
     }
 
-    public function extention_ok(&$env){
-      return $this->EXTENTION_OK;
+    public function default_params(){
+      return array(
+        "host" => "localhost",
+        "base" => "mtweb",
+        "user" => "",
+        "password" => ""
+      );
     }
 
-    public function authentication_required(){
-      return true;
+    public function validate_extention(){
+      return function_exists("mysql_connect");
     }
 
-    public function sgbd_name(){
-      return "MySql";
+    public function authentication_required(){
+      return true;
     }
 
     public function connect($host, $base, $user, $password){
@@ -47,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(
@@ -69,7 +64,8 @@
       return $desc;
     }
 
-    public function table_exists($table_name){\r
+    public function table_exists($table_name){
+      $table_name = $this->replace_prefixes($table_name);\r
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       $EXISTS = false;
       try{
@@ -89,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
       $result = @mysql_query($query_string, $this->link);\r
       if(!$result) throw new Exception($this->exception_out("Syntaxe invalide dans une requete"));\r