Example #1
0
 /**
  * get Singleton class
  * @return Database
  */
 public static function getInstance()
 {
     if (self::$database == NULL) {
         self::$database = new Database();
     }
     return self::$database;
 }
Example #2
0
 public static function getInstance()
 {
     if (!isset(Database::$database)) {
         Database::$database = new Database();
     }
     return Database::$database;
 }
Example #3
0
 public function database()
 {
     if (file_exists(Compose::databasePath())) {
         self::$database = true;
     } else {
         die(Compose::databasePath() . ' does not exist');
     }
 }
Example #4
0
 /**
  * Get an instance of the database object
  * @return Database
  */
 public static function getDbInstance()
 {
     if (self::$database === NULL) {
         self::$database = new Database();
         self::$database->execQuery('SET NAMES utf8;', false);
     }
     return self::$database;
 }
 public static function clearDB()
 {
     self::$database = null;
 }
Example #6
0
 /**
  * Closing the connection.
  *
  * It's not necessary to close the connection, however it's a good practice.
  * "If you don't do this explicitly, PHP will automatically close the connection when your script ends."
  *
  * This will be used at the end "footer.php"
  *
  * @static static method
  * @access public
  * @see http://php.net/manual/en/pdo.connections.php
  */
 public static function closeConnection()
 {
     if (isset(self::$database)) {
         self::$database->connection = null;
         self::$database->statement = null;
         self::$database = null;
     }
 }
Example #7
0
 public static function initialize($databaseName = "", $asAdmin = false)
 {
     // If a database name isn't used, attempt to use a default database.
     if (!$databaseName) {
         $databaseName = self::$databaseName ? self::$databaseName : DATABASE_NAME;
     }
     try {
         self::$database = null;
         $databaseName = Sanitize::variable($databaseName);
         /*
         	http://stackoverflow.com/questions/20079320/php-pdo-mysql-returns-integer-columns-as-strings-on-ubuntu-but-as-integers-o
         	http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo
         	http://stackoverflow.com/questions/10113562/pdo-mysql-use-pdoattr-emulate-prepares-or-not
         */
         // Prepare PDO Options
         $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_STRINGIFY_FETCHES => false);
         if (defined("PDO::MYSQL_ATTR_FOUND_ROWS")) {
             $options[PDO::MYSQL_ATTR_FOUND_ROWS] = false;
         } else {
             $options[1002] = false;
             // Note: 1002 is PDO::MYSQL_ATTR_FOUND_ROWS (fixing issue for some instances)
         }
         // Connect to the database as an admin
         if ($asAdmin) {
             self::$database = new PDO(DATABASE_ENGINE . ":host=" . DATABASE_HOST . ";dbname=" . $databaseName . ";charset=utf8;", DATABASE_ADMIN_USER, DATABASE_ADMIN_PASS, $options);
         } else {
             self::$database = new PDO(DATABASE_ENGINE . ":host=" . DATABASE_HOST . ";dbname=" . $databaseName . ";charset=utf8;", DATABASE_USER, DATABASE_PASS, $options);
         }
         self::$databaseName = $databaseName;
         return true;
     } catch (PDOException $e) {
         // TODO: Use the logging method here to track the exception.
     }
     return false;
 }