<?php
- class mw_pdo_mysql{
+ class mw_pdo_mysql extends mw_sgbd{
- var $link;
-
- var $host;
- var $base;
- var $user;
- var $password;
-
- var $EXTENTION_OK;
+ public function name(){
+ return "PDO MySql";
+ }
- function get_link(){
- return $this->link;
+ public function default_params(){
+ return array(
+ "host" => "localhost",
+ "base" => "mtweb",
+ "user" => "",
+ "password" => ""
+ );
}
- function extention_ok(&$env) { return $this->EXTENTION_OK; }
+ public function validate_extention(){
+ return extension_loaded("pdo") && extension_loaded("pdo_mysql");
+ }
- function mw_pdo_mysql($host, $base, $user, $password){
- $this->host = $host;
- $this->base = $base;
- $this->user = $user;
- $this->password = $password;
- $this->EXTENTION_OK = (extension_loaded("pdo") && extension_loaded("pdo_mysql"));
+ public function authentication_required(){
+ return true;
}
- function connect($host, $base, $user, $password){
+ public function connect($host, $base, $user, $password){
try{
$this->link = new PDO("mysql:host=".$host.";dbname=".$base, $user, $password);
$this->link->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){
+ $table_name = $this->replace_prefixes($table_name);
$sql = "SELECT * from information_schema.columns where table_name='".$table_name."'";
$rst = $this->query($sql);
$desc = array(
return $desc;
}
- function table_exists($table_name){
+ 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);\r
$EXISTS = false;
try{
return $EXISTS;\r
}
- function field_exists($table_name, $field_name){
+ 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);\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){
+ $query_string = $this->replace_prefixes($query_string);\r
if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
if(!($result = $this->link->query($query_string))){
throw new Exception($this->exception_out("Syntaxe invalide dans une requete"));
return $result;\r
}
- function fetch_assoc($rst){
+ public function fetch_assoc($rst){
if(!$this->link){
throw new Exception($this->exception_out("fetch_assoc sans connexion"));
}
return $tuple;
}
- function insert_id(){
+ public function insert_id(){
if(!$this->link){
throw new Exception($this->exception_out("insert_id sans connexion"));
}
return $id;
}
- function free_result($rst){
+ public function free_result($rst){
if(!$this->link){
throw new Exception($this->exception_out("free_result sans connexion"));
}
return true;
}
- function close(){
+ public function close(){
$this->link = null;
return true;
}
- function exception_out($message){\r
+ public function exception_out($message){\r
return "[erreur] mysql : ".$message;\r
}
}
-
-?>
\ No newline at end of file