本文整理汇总了PHP中core\Database::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::get方法的具体用法?PHP Database::get怎么用?PHP Database::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\Database
的用法示例。
在下文中一共展示了Database::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Create a new instance of the database helper.
*/
public function __construct()
{
/**
* connect to PDO here.
*/
$this->db = \Core\Database::get();
}
示例2: __construct
public function __construct()
{
$this->db = Database::get();
}
示例3: getWhere
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;
}
示例4: __construct
/**
* 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');
}
}
示例5: __construct
/**
* create a new instance of the database helper
*/
public function __construct()
{
//connect to PDO here.
$this->db = Database::get();
}