/** * Returns the database connection used by this AR class. * By default, the "db" application component is used as the database connection. * * @return Connection the database connection used by this AR class. */ public static function getDb() { if (empty(self::$_db)) { self::$_db = Application::$app->getDb(); } return self::$_db; }
public static function getDBCon() { if (empty(self::$db)) { self::$db = Service::get('db')->getConnection(); } return self::$db; }
/** * Write empty class of database connection in pdo variable */ public static function closeDBCon() { self::$pdo = Service::get('db')->closeDB(); }
public function __construct() { self::$db = ServiceContainer::get('database'); }
/** * Find and return records from database by param * * @access public * @static * * @param string $record * * @return array|ActiveRecord * @throws \Framework\Exception\DataBaseException * @throws \Framework\Exception\ServiceException */ public static function find($record) { if (!isset(static::$database)) { self::$database = Service::get('dataBase'); } if ($record == static::ALL_RECORDS) { $allRecords = self::$database->selectAll(static::getTable()); $posts = array(); foreach ($allRecords as $rec) { $posts[] = new static($rec); } return $posts; } else { $record = self::$database->select(static::getTable(), array('*'), array('id' => $record)); return new static($record); } }