Esempio n. 1
0
 /**
  * Create a new instance of the database helper.
  */
 public function __construct()
 {
     /**
      * connect to PDO here.
      */
     $this->db = \Core\Database::get();
 }
Esempio n. 2
0
 public function __construct()
 {
     $this->db = Database::get();
 }
Esempio n. 3
0
 public static function getWhere($sql = '', $values = [])
 {
     $database = \Core\Database::get(static::getModelDatabase());
     $data = $database->query('SELECT * FROM `' . static::getModelTable() . '` ' . $sql, $values);
     $data = static::preProcessGetWhere($data);
     if (!is_array($data)) {
         throw new ModelException('Array not returned in Model::getWhere');
     }
     $result = [];
     foreach ($data as $row) {
         $class = get_called_class();
         $model = new $class();
         $model->populate($row);
         $result[] = $model;
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Table builder constructor.
  * Database class initialization, don't create too many instances of table builder,
  * because it will create many database instances which will decrease performance.
  * By default this class would create a `id` field INT(11) NOT null AUTO_INCREMENT PRIMARY KEY, unless
  * you'll set second parameter false.
  *
  * @param PDO|null $db
  *        	- PDO instance (it can be a \helper\database instance)
  * @param boolean $id
  *        	- A flag to add or not to add `id` field automatically
  */
 public function __construct(PDO $db = null, $id = true)
 {
     // If database is not given, create new database instance.
     // database is in the same namespace, we don't need to specify namespace
     $this->db = !$db ? Database::get() : $db;
     if ($id === true) {
         $this->addField('id', 'INT(11)', false, self::AUTO_INCREMENT);
         $this->setPK('id');
     }
 }
Esempio n. 5
0
 /**
  * create a new instance of the database helper
  */
 public function __construct()
 {
     //connect to PDO here.
     $this->db = Database::get();
 }