class mw_pdo_mysql{
- var $link;
-
- var $host;
- var $base;
- var $user;
- var $password;
-
- var $EXTENTION_OK;
+ public $link;
+ public $host;
+ public $base;
+ public $user;
+ public $password;
+ public $EXTENTION_OK;
+
+ public function __construct($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 = (extension_loaded("pdo") && extension_loaded("pdo_mysql"));
+ }
- function get_link(){
+ public function get_link(){
return $this->link;
}
- function extention_ok(&$env) { return $this->EXTENTION_OK; }
-
- function authentication_required() { return true; }
+ public function extention_ok(&$env){
+ return $this->EXTENTION_OK;
+ }
- function sgbd_name() { return "PDO MySql"; }
+ public function authentication_required(){
+ return true;
+ }
- function mw_pdo_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 = (extension_loaded("pdo") && extension_loaded("pdo_mysql"));
+ public function sgbd_name(){
+ return "PDO MySql";
}
- 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){
$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){
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){
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){\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