Example #1
0
 public static function getInstance()
 {
     if (self::$_db === null) {
         self::$_db = new PDO('mysql:dbname=loftblog_dz2;host=localhost', 'root', '');
     }
     return self::$_db;
 }
Example #2
0
 function __construct()
 {
     try {
         self::$_db = new PDO("mysql:host=" . self::$_db_host . ";dbname=" . self::$_db_name, self::$_db_username, self::$_db_password);
     } catch (PDOException $e) {
         echo "Datenbankverbindung gescheitert!";
         die;
     }
 }
Example #3
0
 public function DB($db = null, $usuario = null, $pass = null, $servidor = null)
 {
     $this->DB_Common();
     if ($db && $servidor && $usuario && $pass) {
         DB::$_servidor = $servidor;
         DB::$_db = $db;
         DB::$_usuario = $usuario;
         DB::$_pass = $pass;
     }
     DB::crea_instancia();
 }
 /**
  * makeConnection initializes the DB classes purpose to make a db connection and 
  * initialize the static and protected property
  */
 private function makeConnection()
 {
     $dbstr = self::dbtype . ':';
     $dbstr .= 'host=' . self::host . ';';
     $dbstr .= 'dbname=' . self::dbname;
     if (is_null(self::$_db)) {
         self::$_db = new PDO($dbstr, self::user, self::password, array(PDO::ATTR_PERSISTENT => true));
         $this->addLogEvent('message', 'database has been initialized');
     }
     $this->db = self::$_db;
 }
Example #5
0
 public static function connect()
 {
     // duang duang duang
     DB::$_db = new mysqli(Config::$DB['server'], Config::$DB['username'], Config::$DB['password'], Config::$DB['dbname'], Config::$DB['port']);
     // 处理错误的duang
     if (DB::$_db->connect_error) {
         // 报个错
         die(json_encode((object) ['status' => "faild", 'message' => 'Database Connect Error (' . DB::$_db->connect_errno . ') ' . DB::$_db->connect_error]));
     }
     // 把前缀存起来备用
     $_prefix = Config::$DB['prefix'];
 }
Example #6
0
 /**
  * function getInstance
  *
  * @param array $dbconfig array('ServerName', 'UserName', 'Password', 'DefaultDb', 'DB_Port', 'DB_TYPE')
  * @return DB object
  * @static
  * @access public
  * @throws DBException
  */
 public static function getInstance($dbConfig = null)
 {
     if (!is_array($dbConfig)) {
         $dbConfig = Configure::read("db");
     }
     if (isset(self::$_db) && self::$_config == $dbConfig) {
         return self::$_db;
     }
     self::_initConfig($dbConfig);
     if (!class_exists('PDO')) {
         throw new DBException("PDO isn't supported");
     }
     self::$_db = new DB();
     return self::$_db;
 }
Example #7
0
File: db.php Project: Honvid/HCMS
 public static function getInstance($dbname)
 {
     if (self::$_db == null || self::$_dbname != $dbname) {
         $db = array();
         $db["pconnect"] = false;
         $db["host"] = C($dbname . ".DB_HOST");
         $db["port"] = C($dbname . ".DB_PORT");
         $db["user"] = C($dbname . ".DB_USER");
         $db["pwd"] = C($dbname . ".DB_PWD");
         $db["database"] = C($dbname . ".DB_NAME");
         $db["charset"] = "utf8";
         self::$_dbname = $dbname;
         self::$_db = new DB($db);
     }
     return self::$_db;
 }
Example #8
0
 /**
  * Delete all registered PDO objects in _db array.
  */
 public static function reset_db()
 {
     self::$_db = array();
 }
Example #9
0
 /**
  * 
  * @access private
  * @static
  * @return void
  */
 private static function _connect()
 {
     // return false if db has already connected
     if (self::$_db) {
         return;
     }
     try {
         self::$_db = new mysqli(self::$_dbHost, self::$_dbUser, self::$_dbPass, self::$_dbName);
         self::$_db->set_charset('utf8');
         if (self::$_db->connect_errno) {
             throw new Exception('Cannot connect to DB: ' . self::$_db->connect_error);
         }
     } catch (Exception $e) {
         // trigger caught error
         logMessage('error', $e->getMessage(), TRUE);
         // show error page
         showError('Cannot connect to database.', 'Database Error', 500);
     }
 }
Example #10
0
 /**
  *  Set the DB name
  *
  *  @param string $db Database name
  *
  *  @return void
  */
 public static final function setDb($db)
 {
     self::$_db = $db;
 }
Example #11
0
        echo "<br /><center>#################### I N I C I O ####################</center>";
        if ($comentario || $comentario == 0) {
            echo "<br /><center>--------------------------------------------------------";
            echo "<br />" . $comentario;
            echo "<br />--------------------------------------------------------</center>";
        }
        echo "<br /><table align='center' width='75%' {$style}><tr><td><pre>";
        if ($line) {
            echo "<br />Line: " . $line;
        }
        if ($file) {
            echo "<br />File: " . $file;
        } else {
            echo "<br />Source: " . $_SERVER['PHP_SELF'] . "<br />";
        }
        echo "<br /><center>-------------------------------------------------------------------------------------------------------------------</center>";
        if (is_array($element)) {
            var_export($element ? $element : "Empty!!!");
            echo "</pre></td></tr></table>";
        } else {
            echo "<br />" . ($element || $element == 0 ? $element : "Empty!!!") . "</pre></td></tr></table>";
        }
        echo "<br /><center>#################### F I N ####################</center><br />";
        echo "</div>";
    }
}
$_setup = parse_ini_file("setup.ini", true);
DB::$_usuario = $_setup["credentials"]["_user"];
DB::$_pass = $_setup["credentials"]["_pass"];
DB::$_db = $_setup["credentials"]["_db"];