3 class mw_env_sgbds extends mw_env{
7 public function sgbds(){
8 if(isset($this->sgbds)) return $this->sgbds;
9 $this->sgbds = array();
10 $impls_dir = $this->path("mw_dir")."env/sgbd";
11 if(!file_exists($impls_dir) || !is_dir($impls_dir)){
14 if($dh = opendir($impls_dir)){
16 while($OK && ($impl_file = readdir($dh)) !== false){
17 if(substr($impl_file, 0 ,1) !== "." && substr($impl_file, -4) == ".php"){
18 require_once $impls_dir."/".$impl_file;
19 if(class_exists($class_name = substr($impl_file, 0, -4))){
21 method_exists($class_name, "name")
22 && method_exists($class_name, "extention_ok")
24 $impl = new $class_name($this);
25 if($impl->extention_ok($this)) $this->sgbds[$class_name] = $impl;
37 public function load_sgbd(){
38 if(($data = $this->data()) && $this->bdd("sgbd")){
39 $sgbd_impl_file = $this->path("mw_dir")."env/sgbd/mw_".$this->bdd("sgbd").".php";
40 if(!file_exists($sgbd_impl_file)){
41 $this->erreur("Impossible de trouver le fichier d'implementation du sgbd ".$this->bdd("sgbd"), true);
43 $sgbd_impl = "mw_".$this->bdd("sgbd");
44 if(!class_exists($sgbd_impl)) require_once $sgbd_impl_file;
45 if(!class_exists($sgbd_impl)){
46 $this->erreur("Impossible de trouver la classe d'implementation du sgbd ".$this->bdd("sgbd"), true);
48 $sgbd = new $sgbd_impl(
51 "host" => $this->bdd("host"),
52 "base" => $this->bdd("base"),
53 "user" => $this->bdd("user"),
54 "password" => $this->bdd("password")
57 if(!$sgbd->extention_ok()){
58 $this->erreur("L'extention php ".$this->bdd("sgbd")." n'est pas installée", true);
60 $data->set_sgbd($sgbd);
66 // -------------------------------------------------------------------------------------------
70 abstract class mw_sgbd{
80 public function __construct($env, $params = array()){
82 $default_params = $this->default_params();
83 $params = $this->prepare_params($params);
84 $this->host = isset($params["host"]) ? $params["host"] : $default_params["host"];
85 $this->base = isset($params["base"]) ? $params["base"] : $default_params["base"];
86 $this->user = isset($params["user"]) ? $params["user"] : $default_params["user"];
87 $this->password = isset($params["password"]) ? $params["password"] : $default_params["password"];
88 $this->EXTENTION_OK = $this->validate_extention();
91 public function name(){
95 public function default_params(){
104 public function prepare_params($params){
108 public function validate_extention(){
112 public function authentication_required(){
116 public function get_link(){
120 public function extention_ok(){
121 return $this->EXTENTION_OK;
124 public function replace_prefixes($content){
126 ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
127 str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $content)