MkFramework
 All Data Structures Functions
abstract_sgbd.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 abstract class abstract_sgbd{
24 
25  protected $_tConfig;
26  protected $_sConfig;
27  protected $_sClassRow;
28  protected $_pDb;
29  protected $_sReq;
30  protected $_tId;
31 
32  private static $_tInstance=array();
33 
38  protected static function _getInstance($class,$sConfig) {
39  if ( !isset(self::$_tInstance[$class][$sConfig]) ){
40  $oSgbd = new $class();
41  $oSgbd->chooseConfig($sConfig);
42  self::$_tInstance[$class][$sConfig]=$oSgbd;
43 
44  }
45  return self::$_tInstance[$class][$sConfig];
46  }
47 
53  public function setClassRow($sClassRow){
54  $this->_sClassRow=$sClassRow;
55  }
60  public function chooseConfig($sConfig){
61  $this->_sConfig=$sConfig;
62  }
67  public function setConfig($tConfig){
68  $this->_tConfig=$tConfig;
69  }
73  public function getRequete(){
74  return $this->_sReq;
75  }
80  public function bind($tReq){
81  $sReq='';
82 
83  if(is_array($tReq)){
84  $sReq=$tReq[0];
85  if(isset($tReq[1]) and is_array($tReq[1])){
86  $tParam=$tReq[1];
87  }else{
88  unset($tReq[0]);
89  $tParam=array_values($tReq);
90  }
91 
92  foreach($tParam as $sVal){
93  $sVal=$this->quote($sVal);
94  $sReq=preg_replace('/[?]/',$sVal,$sReq,1);
95  }
96  }else{
97  return $tReq;
98  }
99 
100  return $sReq;
101  }
102 
103  public function getInsertFromTab($tProperty){
104 
105  $sCols='';
106  $sVals='';
107 
108  if($tProperty){
109  foreach($tProperty as $sVar => $sVal){
110  $sCols.=$sVar.',';
111  $sVals.=$this->quote($sVal).',';
112  }
113  }
114  return '('.substr($sCols,0,-1).') VALUES ('.substr($sVals,0,-1).') ';
115  }
116  public function getUpdateFromTab($tProperty){
117  $sReq='';
118  if($tProperty){
119  foreach($tProperty as $sVar => $sVal){
120  $sReq.=$sVar.'='.$this->quote($sVal).',';
121  }
122  }
123  return substr($sReq,0,-1);
124  }
125  public function setId($tId){
126  $this->_tId=$tId;
127  }
128  public function getWhereFromTab($tId){
129  $sWhere='';
130  if(is_array($tId)){
131  foreach($tId as $sVar => $sVal){
132  if($sWhere!=''){ $sWhere.=' AND '; }
133  $sWhere.=$sVar.'='.$this->quote($sVal);
134  }
135  }
136 
137  return $sWhere;
138  }
139  public function erreur($sErreur){
140  throw new Exception($sErreur);
141  }
142 
143 }
static _getInstance($class, $sConfig)
setClassRow($sClassRow)
chooseConfig($sConfig)
setConfig($tConfig)