14 function extention_ok(&$env) { return $this->EXTENTION_OK; }
16 function mw_mysql($host, $base, $user, $password){
20 $this->password = $password;
21 $this->EXTENTION_OK = function_exists("mysql_connect");
24 function connect($host, $base, $user, $password){
25 $this->link = @mysql_connect($host, $user, $password);
26 if(!$this->link) throw new Exception($this->exception_out("Impossible d'etablir une connection au serveur"));
27 @mysql_query("SET NAMES 'utf8'");
29 $connected = @mysql_select_db($base, $this->link);
30 if(!$connected) throw new Exception($this->exception_out("Impossible de selectioner la base ".$base));
35 function select_db($db_name){
\r
36 $this->base = $db_name;
\r
37 if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);
\r
38 return $this->query("USE ".$db_name);
\r
41 function table_exists($table){
\r
42 if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);
\r
43 $rst = $this->query("SHOW TABLES");
\r
44 while($v_rst = mysql_fetch_array($rst)){
\r
45 if(strcmp($v_rst[0], $table) == 0) return true;
\r
47 mysql_free_result($rst);
\r
51 function query($query_string){
\r
52 if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);
\r
53 $result = @mysql_query($query_string, $this->link);
\r
54 if(!$result) throw new Exception($this->exception_out("Syntaxe invalide dans une requete"));
\r
58 function fetch_assoc($rst){
61 return mysql_fetch_assoc($rst);
63 else throw new Exception($this->exception_out("fetch_assoc sans result handler"));
65 else throw new Exception($this->exception_out("fetch_assoc sans connexion"));
70 return mysql_insert_id($this->link);
72 else throw new Exception($this->exception_out("insert_id sans connexion"));
75 function free_result($rst){
78 return mysql_free_result($rst);
80 else throw new Exception($this->exception_out("free_result sans result handler"));
82 else throw new Exception($this->exception_out("free_result sans connexion"));
86 if($this->link) return mysql_close($this->link);
90 function exception_out($message){
\r
91 return "[erreur] mysql : ".$message;
\r