public attr / function, constructeurs __construct
[mtweb] / mw / app / data / impl / mw_mysql.php
index 4f8e41d..8a58384 100644 (file)
@@ -2,22 +2,14 @@
 
   class mw_mysql{
 
-    var $link;
-
-    var $host;
-    var $base;
-    var $user;
-    var $password;
-
-    var $EXTENTION_OK;
-
-    function extention_ok(&$env) { return $this->EXTENTION_OK; }
-
-    function authentication_required() { return true; }
-
-    function sgbd_name() { return "MySql"; }
-
-    function mw_mysql($params = array()){
+    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->EXTENTION_OK = function_exists("mysql_connect");
     }
 
-    function connect($host, $base, $user, $password){
+    public function extention_ok(&$env){
+      return $this->EXTENTION_OK;
+    }
+
+    public function authentication_required(){
+      return true;
+    }
+
+    public function sgbd_name(){
+      return "MySql";
+    }
+
+    public function connect($host, $base, $user, $password){
       $this->link = @mysql_connect($host, $user, $password);
       if(!$this->link) throw new Exception($this->exception_out("Impossible d'etablir une connection au serveur"));
       @mysql_query("SET NAMES 'utf8'");
       return true;
     }
 
-    function select_db($db_name){\r
+    public function select_db($db_name){\r
       $this->base = $db_name;\r
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       return $this->query("USE ".$db_name);\r
     }
 
-    function desc_table($table_name){
+    public function desc_table($table_name){
       $sql = "SELECT * from information_schema.columns where table_name='".$table_name."'";
       $rst = $this->query($sql);
       $desc = array(
@@ -65,7 +69,7 @@
       return $desc;
     }
 
-    function table_exists($table_name){\r
+    public function table_exists($table_name){\r
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
       $EXISTS = false;
       try{
@@ -84,7 +88,7 @@
       return $EXISTS;
     }
 
-    function field_exists($table_name, $field_name){
+    public function field_exists($table_name, $field_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;
     }
 
-    function query($query_string){\r
+    public function query($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
       return $result;\r
     }
 
-    function fetch_assoc($rst){
+    public function fetch_assoc($rst){
       if($this->link){
         if($rst){
           return mysql_fetch_assoc($rst);
       else throw new Exception($this->exception_out("fetch_assoc sans connexion"));
     }
 
-    function insert_id(){
+    public function insert_id(){
       if($this->link){
         return mysql_insert_id($this->link);
       }
       else throw new Exception($this->exception_out("insert_id sans connexion"));
     }
 
-    function free_result($rst){
+    public function free_result($rst){
       if($this->link){
         if($rst){
           return mysql_free_result($rst);
       else throw new Exception($this->exception_out("free_result sans connexion"));
     }
 
-    function close(){
+    public function close(){
       if($this->link) return mysql_close($this->link);
       return true;
     }
 
-    function exception_out($message){\r
+    public function exception_out($message){\r
       return "[erreur] mysql : ".$message;\r
     }
 
   }
-
-?>
\ No newline at end of file