Example #1
0
 /**
  * Set database name for model
  *
  * @param String $name
  */
 public static function setDb($name)
 {
     if (!is_string($name)) {
         trigger_error("Failed to set database name, string expected, \\'" . gettype($name) . "\\' given.");
     }
     static::$database = $name;
 }
Example #2
0
 private static function Initialize($i, $f, $h, $u, $p, $d)
 {
     if (static::$database === null) {
         // Database Interface Factory Model - Include and instantiate database interface class ($i)
         require_once path_classes . 'dbi/' . strtolower($i) . '.php';
         static::$database = new $i();
         self::Link($h, $u, $p, $d, $f);
     }
 }
Example #3
0
 public static function getDb()
 {
     if (!isset(static::$database)) {
         $app = $GLOBALS['app'];
         $pdoConfig = $app->getContainer()['pdo'];
         static::$database = new \Slim\PDO\Database($pdoConfig['uri'] . $pdoConfig['host'] . $pdoConfig['database'], $pdoConfig['username'], $pdoConfig['password']);
     }
     return static::$database;
 }
Example #4
0
 /**
  * A constructor
  *
  * It is called every time the an object is instansiated
  * before the object can be manupilated by the methods.
  * It creates the databse connection to be used.
  *
  */
 public function __construct()
 {
     try {
         static::$database = new PDO('mysql:host=' . static::$host . ';dbname=' . static::$dbName, static::$username, static::$password);
         static::$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $exception) {
         echo "Connection error: " . $exception->getMessage();
     }
 }
Example #5
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $databases = static::getParam('databases');
     static::$database = $databases[static::$driverName];
     $pdo_database = 'pdo_' . static::$driverName;
     if (!extension_loaded('pdo') || !extension_loaded($pdo_database)) {
         static::markTestSkipped('pdo and ' . $pdo_database . ' extension are required.');
     }
     static::runConsoleAction('migrate/up', ['migrationPath' => '@yii/log/migrations/', 'interactive' => false]);
 }
Example #6
0
 private function _factory($database)
 {
     if (empty($database)) {
         throw new Exception('No database specified.', 501);
     }
     if (empty(static::$queryBuilderInstance[$database])) {
         $connection = Connection::getConn($database);
         static::$queryBuilderInstance[$database] = new QueryBuilder($connection);
     }
     static::$database = static::$queryBuilderInstance[$database]->getConnection()->getDatabase();
     return static::$queryBuilderInstance[$database];
 }
 /**
             initDatabase
             This function allows us to create the PDO object based on a ini file.
          **/
 protected static function initDatabase()
 {
     if (file_exists(SELF::CONFIG_FILE)) {
         $data = parse_ini_file(SELF::CONFIG_FILE);
         if (!empty($data['database'])) {
             $db_settings = json_decode($data['database']);
             static::$database = new PDO($db_settings->type . ":host=" . $db_settings->host . ";dbname=" . $db_settings->db_name, $db_settings->username, $db_settings->password);
         } else {
             throw new Exception("ERROR[__construct]: NilFactorDatabase had no settings available to load.");
         }
     } else {
         throw new Exception("ERROR[__construct]: NilFactorDatabase had no settings available to load.");
     }
 }
Example #8
0
 /**
  * Database Facade
  *
  * The `DB` class expects, at the very least, that either the
  * `DatabaseServiceProvider` has been registered or both the
  * `F9\Database` and the `Illuminate\Database` have been properly
  * instantiated and registered with the `Forge` or `Application`.
  */
 public function __construct()
 {
     // we'll need to use the instance for non-static calls
     static::$instance = $this;
     // include only if the framework Database should be used.
     if (config('database.database_enabled')) {
         // get the current database object
         static::$database = Forge::find('Database');
     }
     // include only if eloquent should be used.
     if (config('database.eloquent_enabled')) {
         // get the current illuminate db connection
         static::$connection = Forge::find('db.connection');
     }
 }
Example #9
0
 public static function establish_connection($db_settings_name)
 {
     $obj_db = new \PDO('mysql:host=' . $db_settings_name['host'] . ';dbname=' . $db_settings_name['database'], $db_settings_name['username'], $db_settings_name['password']);
     $obj_db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     static::$database = $obj_db;
 }
Example #10
0
 /**
  * Required
  * connects to the database and stores the connection
  * @param array $db_settings
  */
 public static function establish_connection(array $db_settings)
 {
     static::$database = $db_settings['database'];
     $file = strtolower($db_settings['adapter']) . '_adapter';
     $filename = $file . '.php';
     /**
      * lazy loading of the adapter
      */
     $_adapters = self::get_available_adapters();
     if (isset($_adapters[$filename])) {
         require_once __DIR__ . '/../adapters/' . $filename;
     }
     $class = Inflector::classify($file);
     $klass = new $class($db_settings);
     static::load_interfaces();
     static::$adapter = $klass;
 }
Example #11
0
File: Core.php Project: nblight/mvc
 private function selectDb()
 {
     static::$database = mysqli_select_db(static::$connection, $this->dbname);
 }