Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
function gquery($query)
{
    $dbconn = getConnect();
    $result = pg_query($dbconn, $query) or die('echec de la requete : ' . $query . ' ' . pg_last_error());
    closeConnect();
    return $result;
}
Exemplo n.º 4
0
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);
}