Beispiel #1
0
 private function __construct()
 {
     $host = DB_HOST;
     $username = DB_USER;
     $password = DB_PASS;
     $dbName = DB_NAME;
     if (self::$db == null) {
         $db = new \mysqli($host, $username, $password, $dbName);
         $db->set_charset("utf8");
         if ($db->connect_error) {
             var_dump($db);
             die('Can not connect to database');
         }
         self::$db = $db;
     }
 }
Beispiel #2
0
 private function __construct()
 {
     // build database handler using static read method of Config class to access database credentials
     $this->databaseHandler = new PDO(ConfigDatabase::read('db.engine') . ':host=' . ConfigDatabase::read('db.host') . ';dbname=' . ConfigDatabase::read('db.basename'), ConfigDatabase::read('db.user'), ConfigDatabase::read('db.password'));
 }
Beispiel #3
0
    /**
     * @param string $name Reads value from config array
     * @return void
     */
    public static function read($name)
    {
        return self::$config[$name];
    }
    /**
     * @param string $name Writes name to config array
     * @param string $value Writes value to config array
     * @return void
     */
    public static function write($name, $value)
    {
        self::$config[$name] = $value;
    }
}
/**
 * Assign values to object (localhost)
 *
 */
ConfigDatabase::write('db.user', 'root');
ConfigDatabase::write('db.password', 'password');
ConfigDatabase::write('db.engine', 'mysql');
ConfigDatabase::write('db.host', 'localhost');
ConfigDatabase::write('db.basename', 'smg');
/**
 * Assign values to object (live server)
 * 
 */