public function switchDB($model) { if (strpos($model, '.')) { list($this->fix, $model) = explode(".", $model); } else { $this->fix = NULL; } $this->DB = getConnect($this->getTableName(), $this->getModelName(), $this->conn, $this->fix); return $this; }
public function setDB($model, $tablename = '') { if (empty($tablename)) { $tablename = $model; } if (strpos($model, '.')) { list($fix, $model) = explode(".", $model); } else { $fix = NULL; } $this->DB = getConnect($tablename, $model, $this->conn, $fix); return $this; }
function gquery($query) { $dbconn = getConnect(); $result = pg_query($dbconn, $query) or die('echec de la requete : ' . $query . ' ' . pg_last_error()); closeConnect(); return $result; }
function initModelclass($modelname, $tablename = null, $conn = null) { if ($tablename == null) { $tablename = $modelname; } $string = "DESCRIBE `" . $tablename . "`"; $DB = getConnect($tablename, $modelname, 0, $conn); try { $res = $DB['master']->query($string); $mate = $res->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); } if (is_array($mate)) { //生成基类 if ($conn) { $table = $conn . "_" . $modelname; } else { $table = $modelname; } $newmodelstr = "<?php \n class " . $table . "Base extends model{ \n "; $fields = array(); $types = array(); $newmodelstr .= " public \$tablename='" . $tablename . "';"; foreach ($mate as $key => $value) { $value['Field'] = strtolower($value['Field']); if ($value['Key'] == 'PRI') { $newmodelstr .= "\n public \$PRI='" . $value['Field'] . "';"; if ($value['Extra'] == 'auto_increment') { $newmodelstr .= "\n public \$autoid=true;"; } else { $newmodelstr .= "\n public \$autoid=false;"; } } $fields[$value['Field']] = $value['Default']; $types[$value['Field']] = $value['Type']; } $newmodelstr .= "\n public \$fields=" . var_export($fields, true) . ";"; $newmodelstr .= "\n public \$types=" . var_export($types, true) . ";"; $newmodelstr .= "\n}\n?>"; } file_put_contents(P("modelpath") . "model/" . $table . 'Base.class.php', $newmodelstr); }