本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::addConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::addConnection方法的具体用法?PHP Manager::addConnection怎么用?PHP Manager::addConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Capsule\Manager
的用法示例。
在下文中一共展示了Manager::addConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _makeEloquent
/**
* Setup eloquent database
* @param \Illuminate\Database\Capsule\Manager $capsule
* @throws \Lassi\App\Exception\NotFoundException
* @return \Lassi\App\Database
*/
private function _makeEloquent(Capsule $capsule)
{
// Throw exception if minimum requirements not met
if (!getenv('db_driver') || !getenv('db_name')) {
throw new NotFoundException('App configurations not found.');
}
// Get capsule instance
$this->capsule = $capsule;
// Cache db driver
$db_driver = getenv('db_driver');
// Setup connection defaults
$configs = array('driver' => $db_driver, 'database' => getenv('db_name'), 'prefix' => getenv('db_prefix'), 'charset' => getenv('db_charset'), 'collation' => getenv('db_collation'));
// Add extras depending on type of driver/connection
if ($db_driver !== 'sqlite') {
if (getenv('db_host')) {
$configs['host'] = getenv('db_host');
}
if (getenv('db_username')) {
$configs['username'] = getenv('db_username');
}
if (getenv('db_password')) {
$configs['password'] = getenv('db_password');
}
}
// Setup connection
$this->capsule->addConnection($configs);
// Set as global
$this->capsule->setAsGlobal();
// Boot eloquent
$this->capsule->bootEloquent();
return $this;
}
示例2: init
public function init()
{
$this->capsule = new Capsule();
$this->capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'port' => DB_PORT, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => DB_CHARSET, 'collation' => DB_COLLATION]);
$this->capsule->bootEloquent();
$this->capsule->setAsGlobal();
}
示例3: __construct
private function __construct()
{
$this->capsule = new Capsule();
$this->capsule->addConnection(['driver' => 'mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '']);
$this->capsule->setEventDispatcher(new Dispatcher(new Container()));
$this->capsule->setAsGlobal();
}
示例4: setConnection
protected function setConnection(array $connection)
{
$this->capsule = new Capsule();
$this->capsule->addConnection($connection);
$this->capsule->setAsGlobal();
$this->capsule->bootEloquent();
}
示例5: setUpDatabase
protected function setUpDatabase()
{
$db = new DB();
$db->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default');
$db->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'alt');
$db->bootEloquent();
$db->setAsGlobal();
}
示例6: getCapsule
/**
* @return \Illuminate\Database\Capsule\Manager
*/
public function getCapsule()
{
if (!$this->capsule) {
$this->capsule = new Capsule();
$this->capsule->addConnection($this->configuration);
$this->capsule->setAsGlobal();
}
return $this->capsule;
}
示例7: createConnection
protected function createConnection()
{
$this->capsule = new Capsule();
$this->capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/db/testing.sqlite', 'prefix' => '']);
$this->capsule->setFetchMode(PDO::FETCH_CLASS);
$this->capsule->setAsGlobal();
$this->capsule->bootEloquent();
$this->capsule->getConnection()->enableQueryLog();
}
示例8: bootstrap
/**
* {@inheritdoc}
*/
public function bootstrap($app)
{
$this->capsule = new Manager();
$this->capsule->addConnection(['driver' => $this->driver, 'host' => $this->host, 'database' => $this->database, 'username' => $this->username, 'password' => $this->password, 'charset' => $this->charset, 'collation' => $this->collation, 'prefix' => $this->prefix]);
$this->capsule->setEventDispatcher(new Dispatcher(new Container()));
$this->capsule->setAsGlobal();
$this->capsule->bootEloquent();
$app->set('db', $this->capsule);
}
示例9: setUpBeforeClass
/**
* set up eloquent for test
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$manager = new Manager();
// TODO: add dotenv and extract for reuse
self::$manager->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'grimm', 'username' => 'homestead', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null]);
self::$manager->setAsGlobal();
self::$manager->bootEloquent();
}
示例10: addDbConnection
/**
* @param array $credentials
*/
public function addDbConnection($credentials = [])
{
if (empty($credentials)) {
$bitrixDbCredentials = \Bitrix\Main\Application::getInstance()->getConnection()->getConfiguration();
$credentials = ['driver' => 'mysql', 'database' => $bitrixDbCredentials['database'], 'username' => $bitrixDbCredentials['login'], 'password' => $bitrixDbCredentials['password'], 'host' => $bitrixDbCredentials['host'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false];
}
$this->capsule->addConnection($credentials);
$this->capsule->setAsGlobal();
$this->capsule->bootEloquent();
}
示例11: __construct
/**
* Database constructor.
*/
public function __construct()
{
$this->capsule = new Manager();
/**
* Add a connection
*/
$this->capsule->addConnection($this->GetDatabaseSettings());
/**
* Globalise it
*/
$this->capsule->setAsGlobal();
}
示例12: openDatabaseConnection
/**
* Open the database connection with the credentials from application/config/config.php
*/
private function openDatabaseConnection()
{
$capsule = new Capsule();
if (DB_DRIVER == 'sqlite') {
$capsule->addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/../database/api.sqlite3', 'prefix' => '']);
}
if (DB_DRIVER == 'mysql') {
$capsule->addConnection(['driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASS, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false]);
}
$capsule->setAsGlobal();
//make connection available globally
$capsule->bootEloquent();
}
示例13: instance
/**
* @return \Illuminate\Database\Capsule\Manager
*/
public static function instance()
{
if (static::$_instance === null) {
$config = Config::get("database");
static::$_instance = new \Illuminate\Database\Capsule\Manager();
if ($config["connections"] && is_array($config["connections"])) {
foreach ($config["connections"] as $key => $cfg) {
static::$_instance->addConnection($cfg, $key);
}
}
static::$_instance->setAsGlobal();
}
return static::$_instance;
}
示例14: CreateConnection
/**
* Create the connection
*
* @return bool
*/
public function CreateConnection()
{
$information = $this->GetInformation();
if ($information == null) {
return false;
}
try {
$this->database->addConnection($information);
$this->database->setAsGlobal();
} catch (\Exception $error) {
return false;
}
return true;
}
示例15: __construct
public function __construct()
{
$config = Tempest::get()->config->get('db');
if (!empty($config)) {
$config = array_merge(array('driver' => 'mysql', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci'), $config);
$connection = $this->parseConnectionString(ObjectUtil::getDeepValue($config, 'connection'));
$connection = array_merge($config, $connection);
$this->_capsule = new Manager();
$this->_capsule->addConnection($connection);
$this->_capsule->setAsGlobal();
$this->_capsule->bootEloquent();
} else {
throw new Exception('No database connection details were provided by the application.');
}
}