Beispiel #1
0
 /**
  * @param $name
  * @param string $env
  * @return Mysql
  * @throws \Exception
  */
 public static function instance($name, $env = 'product')
 {
     if (empty(self::$_configs)) {
         self::$_configs = \Config\Database::getConfig($name, $env);
     }
     if (!isset(self::$_instances[$name])) {
         $instance = new Mysql(self::$_configs['host'], self::$_configs['user'], self::$_configs['password'], self::$_configs['database']);
         self::$_instances[$name] = $instance;
         return self::$_instances[$name];
     }
     return self::$_instances[$name];
 }
Beispiel #2
0
 public function __construct($args = array())
 {
     $args = array_merge(array('where' => '', 'columns' => '*', 'limit' => 100), $args);
     if (!isset($args['table'])) {
         die('Table not defined.');
     }
     extract($args);
     $this->table = $table;
     $this->where = $where;
     $this->columns = $columns;
     $this->limit = $limit;
     $db_object = \Config\Database::get_instance();
     $this->dbConn = $db_object::get_db();
 }
Beispiel #3
0
if (!empty($request)) {
    if (strpos($request, $request_home) === 0) {
        $request = substr($request, strlen($request_home));
        if (strpos($request, 'admin/') === 0) {
            $admin_routing = true;
            include_once 'controllers/admin/admin_controller.php';
            $request = substr($request, strlen('admin/'));
        }
        $components = explode('/', $request, 3);
        if (count($components) > 1) {
            list($controller, $method) = $components;
            if (!$method) {
                $method = 'index';
            }
            $params = isset($components[2]) ? $components[2] : array();
            $admin_folder = $admin_routing ? 'admin/' : '';
            $pathToControllerFile = 'controllers/' . $admin_folder . $controller . '_controller.php';
            include_once $pathToControllerFile;
        }
    }
}
$admin_namespace = $admin_routing ? 'Admin' : '';
$controller_class = $admin_namespace . '\\Controllers\\' . ucfirst($controller) . '_Controller';
$instance = new $controller_class();
if (method_exists($instance, $method)) {
    call_user_func_array(array($instance, $method), array($params));
} else {
    die('No such method');
}
$db_object = Database::get_instance();
$db_connection = $db_object::get_db();
Beispiel #4
0
 /**
  * Constructor.
  * 
  * @param \CodeIgniter\Database\Forge $forge
  */
 public function __construct(Forge $forge = null)
 {
     $this->forge = !is_null($forge) ? $forge : \Config\Database::forge($this->DBGroup);
     $this->db = $this->forge->getConnection();
 }
Beispiel #5
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->connections = \Config\Database::getConnections();
 }
 public function loadDependencies()
 {
     if ($this->db === null) {
         $this->db = \Config\Database::connect($this->DBGroup);
         $this->db->initialize();
     }
     if ($this->migrations === null) {
         // Ensure that we can run migrations
         $config = new \Config\Migrations();
         $config->enabled = true;
         $this->migrations = Services::migrations($config, $this->db);
         $this->migrations->setSilent(true);
     }
     if ($this->seeder === null) {
         $this->seeder = \Config\Database::seeder($this->DBGroup);
         $this->seeder->setSilent(true);
     }
 }
Beispiel #7
0
 /**
  * Provides a shared instance of the Query Builder.
  *
  * @param string $table
  *
  * @return BaseBuilder|Database\QueryBuilder
  */
 protected function builder(string $table = null)
 {
     if ($this->builder instanceof BaseBuilder) {
         return $this->builder;
     }
     $table = empty($table) ? $this->table : $table;
     // Ensure we have a good db connection
     if (!$this->db instanceof BaseConnection) {
         $this->db = Database::connect($this->DBGroup);
     }
     $this->builder = $this->db->table($table);
     return $this->builder;
 }
Beispiel #8
0
 /**
  * Seeder constructor.
  *
  * @param BaseConfig $config
  * @param BaseConnection $db
  */
 public function __construct(BaseConfig $config, BaseConnection $db = null)
 {
     $this->seedPath = $config->filesPath ?? APPPATH . 'Database/';
     if (empty($this->seedPath)) {
         throw new \InvalidArgumentException('Invalid filesPath set in the Config\\Database.');
     }
     $this->seedPath = rtrim($this->seedPath, '/') . '/Seeds/';
     if (!is_dir($this->seedPath)) {
         throw new \InvalidArgumentException('Unable to locate the seeds directory. Please check Config\\Database::filesPath');
     }
     $this->config =& $config;
     if (is_null($db)) {
         $db = \Config\Database::connect($this->DBGroup);
     }
     $this->db =& $db;
 }
Beispiel #9
0
 function __construct()
 {
     $this->db = new Data\Db(Database::get());
 }
 /**
  * Ensures that we have created our migrations table
  * in the database.
  */
 protected function ensureTable()
 {
     if ($this->db->tableExists($this->table)) {
         return;
     }
     $forge = \Config\Database::forge();
     $forge->addField(['version' => ['type' => 'BIGINT', 'constraint' => 20, 'null' => false], 'group' => ['type' => 'varchar', 'constraint' => 255, 'null' => false], 'time' => ['type' => 'timestamp', 'null' => false]]);
     $forge->createTable($this->table, true);
 }