X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fapp%2Fdata%2Fimpl%2Fmw_mysql.php;h=ba8f56a13a1a4c4e17f7c2c3c6b09f105f833e59;hb=beb400a195a5ac025eb9fe75c5abdeddde4195c2;hp=0cff0c20bf5cccd3d1c6bc4fc0bae891be7c4115;hpb=36ed114046cbe3d72a3589230e9f306a54fcc79d;p=mtweb diff --git a/mw/app/data/impl/mw_mysql.php b/mw/app/data/impl/mw_mysql.php index 0cff0c2..ba8f56a 100644 --- a/mw/app/data/impl/mw_mysql.php +++ b/mw/app/data/impl/mw_mysql.php @@ -38,6 +38,29 @@ return $this->query("USE ".$db_name); } + function desc_table($table_name){ + $sql = "SELECT * from information_schema.columns where table_name='".$table_name."'"; + $rst = $this->query($sql); + $desc = array( + "name" => $table_name, + "attributs" => array() + ); + try{ + while($v_rst = $this->fetch_assoc($rst)){ + $desc["attributs"][$v_rst["COLUMN_NAME"]] = array( + "name" => $v_rst["COLUMN_NAME"], + "prymary_key" => $v_rst["COLUMN_KEY"] == "PRI" ? true : false, + "auto_increment" => $v_rst["EXTRA"] == "auto_increment" ? true : false + ); + } + $this->free_result($rst); + } + catch(Exception $e){ + throw new Exception($this->exception_out("Impossible de lire la description de la table")); + } + return $desc; + } + function table_exists($table){ if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); $rst = $this->query("SHOW TABLES"); @@ -48,6 +71,17 @@ return false; } + 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; + } + function query($query_string){ if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); $result = @mysql_query($query_string, $this->link);