X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fapp%2Fdata%2Fimpl%2Fmw_mysql.php;h=4f8e41d9702232581165eeadbf4bdd5d996ef821;hb=61f37fc21cac669aa439d0681590f5ceccad3157;hp=ba8f56a13a1a4c4e17f7c2c3c6b09f105f833e59;hpb=422d883e3ed8ee55ee41e3b7826f32b79cea646d;p=mtweb diff --git a/mw/app/data/impl/mw_mysql.php b/mw/app/data/impl/mw_mysql.php index ba8f56a..4f8e41d 100644 --- a/mw/app/data/impl/mw_mysql.php +++ b/mw/app/data/impl/mw_mysql.php @@ -13,11 +13,15 @@ function extention_ok(&$env) { return $this->EXTENTION_OK; } - function mw_mysql($host, $base, $user, $password){ - $this->host = $host; - $this->base = $base; - $this->user = $user; - $this->password = $password; + function authentication_required() { return true; } + + function sgbd_name() { return "MySql"; } + + function mw_mysql($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"); } @@ -61,25 +65,38 @@ return $desc; } - function table_exists($table){ + function table_exists($table_name){ if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); - $rst = $this->query("SHOW TABLES"); - while($v_rst = mysql_fetch_array($rst)){ - if(strcmp($v_rst[0], $table) == 0) return true; - } - mysql_free_result($rst); - return false; + $EXISTS = false; + try{ + $rst = $this->query("SHOW TABLES"); + while($v_rst = mysql_fetch_row($rst)){ + if($v_rst[0] == $table_name){ + $EXISTS = true; + break; + } + } + $this->free_result($rst); + } + catch(Exception $e){ + throw new Exception($this->exception_out("Impossible de savoir si la table existe")); + } + return $EXISTS; } function field_exists($table_name, $field_name){ - if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); - $sql = "SHOW COLUMNS FROM `".$table_name."` LIKE ".$field_name; - $rst = $this->query($sql); - $exists = false; - $v_rst = $this->fetch_assoc($rst); - if($v_rst) $exists = true; - $this->free_result($rst); - return $exists; + if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); + if(!($desc = $this->desc_table($table_name))){ + throw new Exception($this->exception_out("Impossible de lire la description de la table")); + } + $EXISTS = false; + foreach($desc["attributs"] as $attribut_name => $attribut){ + if($field_name == $attribut_name){ + $EXISTS = true; + break; + } + } + return $EXISTS; } function query($query_string){