本文整理汇总了PHP中Model::db方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::db方法的具体用法?PHP Model::db怎么用?PHP Model::db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: StartApp
public static function StartApp()
{
ob_start('ob_gzhandler');
session_start();
// Defines
define('BASEURL', substr((empty($_SERVER['HTTPS']) ? 'http://' : 'https://' ) . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'],0,-10));
define('BASEPATH', substr($_SERVER['SCRIPT_FILENAME'],0,-10));
// Helper Boot Loader
require(BASEPATH.'/core/bootloader.php');
// Initialize Helpers
BootLoader::loadHelpers();
Registry::getInstance();
// Handle Errors
Registry::setDebugMode(true);
set_error_handler('Template::handleError');
set_exception_handler('Template::handleException');
// Initialize Database
Model::$db = DBO::getInstance('sqlite:example.sqldb');
// Init Autoloads
spl_autoload_register('Autoload::controllers');
spl_autoload_register('Autoload::models');
// Determine Controllers and Methods
Routes::getRoute();
// Run Application
Routes::run();
}
示例2:
/**
* 构造函数
*
*/
function __construct()
{
// 获取数据库操作对象
if (self::$db == null) {
self::$db = base::get_instance()->db;
}
$this->cache =& $GLOBALS['memcached'];
}
示例3: nuevaDb
protected static function nuevaDb()
{
include_once SYS_PATH . 'DataBase.php';
if (!isset(Model::$db)) {
Model::$db = new DataBase();
}
return Model::$db;
}
示例4: __construct
public function __construct($data = null, $rawData = false)
{
self::$services = ServiceContainer::getInstance();
self::$db = self::$services->get('db');
$this->initialize();
if ($data) {
$rawData ? $this->setRawData($data) : $this->setData($data);
}
}
示例5: setDataSourse
/**
* Set a PDO connection to be reused
*/
private static function setDataSourse()
{
try {
$datasoursename = DBConfig::TYPE . ':host=' . DBConfig::HOST . ';dbname=' . DBConfig::NAME;
$options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
self::$db = new PDO($datasoursename, DBConfig::USER, DBConfig::PASS, $options);
} catch (PDOException $e) {
exit('Database connection could not be established.');
}
}
示例6: __construct
/**
* Creates a PDO connection to MySQL
*
* @return boolean Returns TRUE on success (dies on failure)
*/
public function __construct()
{
$dsn = 'mysql:dbname=' . DB_NAME . ';host=' . DB_HOST;
try {
self::$db = new PDO($dsn, DB_USER, DB_PASS);
} catch (PDOExeption $e) {
die("Couldn't connect to the database.");
}
return TRUE;
}
示例7: _construct
/**
* Creates a PDO connection to your datebase.
*
* @return boolean
*/
public function _construct()
{
$dsn = 'mysql:dbname' . DB_NAME . ';host=' . DB_HOST;
try {
self::$db = new PDO($dsn, DB_USER, DB_PASS);
} catch (PDOException $e) {
$echoError = new Error($e);
exit;
}
return TRUE;
}
示例8: getBd
/**
* Renvoie un objet de connexion à la BD en initialisant la connexion au besoin
*
* @return PDO L'objet PDO de connexion à la BDD
*/
private static function getBd()
{
if (self::$db == null) {
// Récupération des paramètres de configuration BD
$connection = Configuration::get("connection");
$login = Configuration::get("login");
$password = Configuration::get("password");
// Création de la connexion
self::$db = new PDO($connection, $login, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
return self::$db;
}
示例9: getDb
/**
* This function is used to create a connexion to the database with PDO
* @return PDO Object
*/
private function getDb()
{
if (self::$db === null) {
//recovery of configuration parameters to connect to the database
$dsn = Configuration::get("dsn");
$login = Configuration::get("login");
$password = Configuration::get("password");
//Creation of the connexion
self::$db = new PDO($dsn, $login, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
return self::$db;
}
示例10: getInstance
public static function getInstance()
{
if (!isset(self::$db)) {
try {
self::$db = new \PDO('mysql:host=' . 'localhost' . ';dbname=' . 'teste', 'root', '1234');
self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
self::$db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
} catch (PDOException $e) {
die("Erro na Conexão: " . $e->getMessage());
}
}
return self::$db;
}
示例11: init
static function init()
{
Model::db();
Model::check_login();
foreach (glob(APP_PATH . SL . 'actionHelpers/*.php') as $file) {
/** @noinspection PhpIncludeInspection */
include_once $file;
}
global $titlePage;
global $config;
$titlePage = $config['settings']['title'];
Route::launch();
}
示例12: __construct
public function __construct(array $_data = array())
{
if (!isset(self::$db)) {
self::$db = Core::getDb();
}
if (!isset(self::$request)) {
self::$request = Core::$request;
}
if (!isset(self::$profile)) {
self::$profile = Auth::$profile;
self::$uid = self::$profile->user_id;
}
if (isset($_data)) {
$this->_data = $_data;
}
}
示例13: __construct
/**
*构造函数
*
*完成数据库的链接
*/
public function __construct()
{
//打开数据库
$dns = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME;
try {
if (!isset(self::$db)) {
//实例化PDO
self::$db = new PDO($dns, DB_USER, DB_PASS);
//开启异常处理模式
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//设置字符集
self::$db->query('set names ' . DB_CHARSET);
}
} catch (PDOException $e) {
die('无法打开数据库');
}
}
示例14: __construct
/**
* 自动初始化
* @param string $name 表名
* @param string $prefix 前缀
* @param string $connect 连接数据库的类型
* @param string $alias 別名
* @author wave
*/
public function __construct($name = null, $prefix = null, $connect = null, $alias = null)
{
$this->_initialize();
$this->prefix = $prefix;
$this->name = $this->prefix . $name;
$this->alias = $alias;
$this->connect = $connect;
if (empty(self::$db)) {
//防止多次加載
load('config.php', APP_PATH . DS . DATABASE);
//数据库配置文件
load('db.class.php', ROOT_PATH);
//加载连接数据库类
if (!empty($this->connect)) {
self::$db = !empty($this->connect) ? self::link($this->connect) : 1;
//进行初始化数据
} else {
self::$db = isset(config::$default) ? self::link(config::$default) : 1;
}
}
}
示例15: connect
public static function connect($server = "development")
{
$dbYaml = DB::getParse();
self::$db = DB::connect($dbYaml[$server]['host'], $dbYaml[$server]['username'], $dbYaml[$server]['password'], $dbYaml[$server]['database']);
}