X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fapp%2Fdata%2Fimpl%2Fmw_pdo_sqlite.php;fp=mw%2Fapp%2Fdata%2Fimpl%2Fmw_pdo_sqlite.php;h=0000000000000000000000000000000000000000;hb=ad9756b0b72852c82165e824570f21b039fcb359;hp=918bc8af1a9fe0d08ad720d88453d6ffaee91e42;hpb=8da84cf3aa4d10d91f19b6df06ce4c5e9fcb79da;p=mtweb diff --git a/mw/app/data/impl/mw_pdo_sqlite.php b/mw/app/data/impl/mw_pdo_sqlite.php deleted file mode 100644 index 918bc8a..0000000 --- a/mw/app/data/impl/mw_pdo_sqlite.php +++ /dev/null @@ -1,171 +0,0 @@ - "content/data/sqlite", - "base" => "mtweb.db", - "user" => "", - "password" => "" - ); - } - - public function validate_extention(){ - return extension_loaded("pdo") && extension_loaded("pdo_sqlite"); - } - - public function authentication_required(){ - return false; - } - - public function connect($host, $base, $user, $password){ - if($host) $host .= substr($host, -1) != "/" ? "/" : ""; - try{ - $this->link = null; - $this->link = new PDO("sqlite:".$host.$base); - $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->link->query("PRAGMA encoding = 'UTF-8'"); - } - catch(PDOException $e){ - throw new Exception($this->exception_out("Impossible d'etablir une connection au serveur")); - } - return true; - } - - public function select_db($db_name){ - $this->base = $db_name; - return $this->connect($this->host, $this->base, $this->user, $this->password); - } - - public function desc_table($table_name){ - $table_name = $this->replace_prefixes($table_name); - if(strpos($table_name, "'") !== false){ - throw new Exception($this->exception_out("nom de table avec un simple quote")); - } - $desc = array( - "name" => $table_name, - "attributs" => array() - ); - $sql = "PRAGMA table_info(".$table_name.")"; - try{ - $rst = $this->query($sql); - while($v_rst = $this->fetch_assoc($rst)){ - $desc["attributs"][$v_rst["name"]] = array( - "name" => $v_rst["name"], - "prymary_key" => isset($v_rst["pk"]) && $v_rst["pk"] ? true : false - ); - } - $this->free_result($rst); - } - catch(Exception $e){ - throw new Exception($this->exception_out("impossible de lire les champs de la table ".$table_name)); - } - return $desc; - } - - public function table_exists($table_name){ - $table_name = $this->replace_prefixes($table_name); - if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); - $EXISTS = false; - try{ - $rst = $this->query("SELECT name FROM sqlite_master WHERE type='table'"); - while($v_rst = $rst->fetch()){ - 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; - } - - 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); - 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; - } - - public function query($query_string){ - $query_string = $this->replace_prefixes($query_string); - if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password); - if(!($result = $this->link->query($query_string))){ - throw new Exception($this->exception_out("Syntaxe invalide dans une requete")); - } - return $result; - } - - public function fetch_assoc($rst){ - if(!$this->link){ - throw new Exception($this->exception_out("fetch_assoc sans connexion")); - } - if(!$rst){ - throw new Exception($this->exception_out("fetch_assoc sans result handler")); - } - try{ - $tuple = $rst->fetch(PDO::FETCH_ASSOC); - } - catch(Exception $e){ - throw new Exception($this->exception_out("erreur fetch_assoc")); - } - return $tuple; - } - - public function insert_id(){ - if(!$this->link){ - throw new Exception($this->exception_out("insert_id sans connexion")); - } - try{ - $id = $this->link->lastInsertId(); - } - catch(Exception $e){ - throw new Exception($this->exception_out("erreur insert_id")); - } - return $id; - } - - public function free_result($rst){ - if(!$this->link){ - throw new Exception($this->exception_out("free_result sans connexion")); - } - if(!$rst){ - throw new Exception($this->exception_out("free_result sans result handler")); - } - try{ - $rst->closeCursor(); - $rst = null; - } - catch(Exception $e){ - throw new Exception($this->exception_out("erreur free_result")); - } - return true; - } - - public function close(){ - $this->link = null; - return true; - } - - public function exception_out($message){ - return "[erreur] sqlite : ".$message; - } - - }