本文整理汇总了PHP中RedBeanPHP\R::addDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP R::addDatabase方法的具体用法?PHP R::addDatabase怎么用?PHP R::addDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\R
的用法示例。
在下文中一共展示了R::addDatabase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
function connect()
{
$config = \configuration\load();
if (empty($config['dsn']) || empty($config['user']) || empty($config['password'])) {
die("Please check the configuration\\database.php file");
}
R::addDatabase('db', $config['dsn'], $config['user'], $config['password'], $config['frozen']);
R::selectDatabase('db');
}
示例2: __construct
/**
* @param array $db
* @throws \Exception
*/
public function __construct($db = [])
{
$this->db = $db;
$this->cache = isset($db['dev']) && $db['dev'] ? true : false;
foreach ($this->db as $key => $db) {
if (!isset($db['user']) || !isset($db['pass']) || !isset($db['host']) || !isset($db['db'])) {
throw new \Exception('Missing arguments for RedBean constructor');
}
$db['driver'] == 'sqlite' ? R::addDatabase($key, 'sqlite:/tmp/dbfile.db') : R::addDatabase($key, $db['driver'] . ':host=' . $db['host'] . ';dbname=' . $db['db'], $db['user'], $db['pass']);
}
}
示例3: init
protected static function init()
{
if (self::$_inited) {
return;
}
$c = static::conf();
shuffle($c['write']);
shuffle($c['read']);
self::$_mcs = $c['write'];
self::$_scs = array_merge($c['read'], $c['write']);
R::setup();
foreach (self::$_mcs as $i => $c) {
R::addDatabase("write:{$i}", sprintf('mysql:host=%s;port=%d;dbname=%s', $c['host'], $c['port'], $c['dbname']), $c['username'], $c['password']);
}
foreach (self::$_scs as $i => $c) {
R::addDatabase("read:{$i}", sprintf('mysql:host=%s;port=%d;dbname=%s', $c['host'], $c['port'], $c['dbname']), $c['username'], $c['password']);
}
self::$_inited = true;
}