当前位置: 首页>>代码示例>>PHP>>正文


PHP Manager::getConnection方法代码示例

本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::getConnection方法的具体用法?PHP Manager::getConnection怎么用?PHP Manager::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Capsule\Manager的用法示例。


在下文中一共展示了Manager::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setDatabase

 private function setDatabase($dbConfig)
 {
     $capsule = new Capsule();
     $capsule->addConnection($dbConfig, $this->connName);
     $this->set('db', $capsule->getConnection($this->connName));
     //set model conn for all models
     $resolver = new \Illuminate\Database\ConnectionResolver();
     $resolver->addConnection($this->connName, $capsule->getConnection($this->connName));
     $resolver->setDefaultConnection($this->connName);
     \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
 }
开发者ID:hosannahighertech,项目名称:upendo,代码行数:11,代码来源:App.php

示例2: getConnection

 /**
  * Get a registered connection instance.
  *
  * @param string $name
  * @return \Illuminate\Database\Connection
  */
 public function getConnection($connection)
 {
     return $this->capsule->getConnection($connection);
 }
开发者ID:larrytech,项目名称:calendar,代码行数:10,代码来源:Connector.php

示例3: assertQueryCount

 protected function assertQueryCount($expectedCount)
 {
     $log = $this->capsule->getConnection()->getQueryLog();
     $this->assertEquals($expectedCount, count($log), 'Expected ' . $expectedCount . ' queries, got ' . count($log));
 }
开发者ID:leloulight,项目名称:trigglog,代码行数:5,代码来源:TestCase.php

示例4: connection

 /**
  * Returns an instance of the Illuminate Database connection having the specified name, or the default connection if
  * no name is given.
  *
  * @param string $connectionName [optional] A connection name, if you want to use a connection other than the default.
  * @return \Illuminate\Database\Connection
  */
 public function connection($connectionName = 'default')
 {
     $connectionName = $connectionName ?: $this->defaultConnection;
     try {
         return $this->manager->getConnection($connectionName);
     } catch (\InvalidArgumentException $e) {
         $connectionName = $connectionName ?: 'default';
         $con = $this->connections->get($connectionName);
         $this->manager->addConnection($con->getProperties(), $connectionName);
         return $this->manager->getConnection($connectionName);
     }
 }
开发者ID:electro-modules,项目名称:illuminate-database,代码行数:19,代码来源:DatabaseAPI.php

示例5: dispatch

 /**
  * @param array $config
  * @return \Slim\Slim
  */
 public function dispatch($config)
 {
     \Slim\Environment::mock(array('REQUEST_METHOD' => 'HEAD', 'PATH_INFO' => '/'));
     $config['debug'] = false;
     // ignore pretty exceptions
     $slim = new \Slim\Slim($config);
     $manager = new \Slim\Middleware\SessionManager($slim);
     $manager->setDbConnection($this->capsule->getConnection());
     $session = new \Slim\Middleware\Session($manager);
     $slim->add($session);
     $slim->run();
     return $slim;
 }
开发者ID:yusukezzz,项目名称:slim-session-manager,代码行数:17,代码来源:SessionTest.php

示例6: _initORM

 /**
  * Initialize illuminate/database
  *
  * @param Yaf\Dispatcher $dispatcher
  */
 protected function _initORM(Yaf\Dispatcher $dispatcher)
 {
     $dbConfig = Yaf\Application::app()->getConfig()->database->toArray();
     $db = new Capsule();
     $db->addConnection($dbConfig);
     $db->bootEloquent();
     Yaf\Registry::set('db', $db->getConnection());
 }
开发者ID:cooltime,项目名称:material,代码行数:13,代码来源:Bootstrap.php

示例7: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $config = (require __DIR__ . '/../config.php');
     $capsule = new Manager();
     $capsule->addConnection($config);
     $capsule->bootEloquent();
     Schema::setConnection($capsule->getConnection('default'));
     DB::setConnection($capsule->getConnection('default'));
     // run the migrations
     $migration_repo = new DatabaseMigrationRepository(Model::getConnectionResolver(), 'migrations');
     if (!$migration_repo->repositoryExists()) {
         $migration_repo->createRepository();
     }
     $migrator = new Migrator($migration_repo, Model::getConnectionResolver(), new Filesystem());
     $migrator->rollback();
     $migrator->run(__DIR__ . '/../../src/migrations');
     static::loadFixtures();
 }
开发者ID:dadleyy,项目名称:lvpress,代码行数:19,代码来源:TestCase.php

示例8: initDb

 protected function initDb()
 {
     $capsule = new Manager();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', 'fetch' => PDO::FETCH_CLASS]);
     $capsule->getConnection()->setFetchMode(PDO::FETCH_CLASS);
     $capsule->setAsGlobal();
     $capsule->bootEloquent();
     $this->db = $capsule->getDatabaseManager();
     $this->createTables();
     $this->initMuffing();
     return $this->db;
 }
开发者ID:pnagaraju25,项目名称:tbmsg,代码行数:12,代码来源:TestCaseDb.php

示例9: setup

 /**
  * Setup the database service.
  *
  * @param \Slim\Slim $app The application instance.
  */
 public static function setup(Slim $app)
 {
     $manager = new Manager();
     $manager->addConnection(['driver' => $app->config('db.driver'), 'host' => $app->config('db.host'), 'database' => $app->config('db.database'), 'username' => $app->config('db.username'), 'password' => $app->config('db.password'), 'charset' => $app->config('db.charset'), 'collation' => $app->config('db.collation'), 'prefix' => $app->config('db.prefix')]);
     $manager->setEventDispatcher(new Dispatcher(new Container()));
     $manager->setAsGlobal();
     $manager->bootEloquent();
     // Setting database connection to use the same time zone as
     // application.
     $manager->getConnection()->statement('SET time_zone = ?', [Carbon::now()->offsetHours . ':00']);
     $app->database = $manager;
 }
开发者ID:creativeduo,项目名称:thin,代码行数:17,代码来源:Database.php

示例10: getCapsule

 protected function getCapsule()
 {
     $capsule = new Capsule();
     $capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
     /**
      * Swap PDO instance so that we're using the same in-memory
      * database migrated by Phinx.
      */
     $capsule->getConnection()->setPdo($this->phinxPdo);
     $capsule->setAsGlobal();
     return $capsule;
 }
开发者ID:intfrr,项目名称:opencfp,代码行数:12,代码来源:DatabaseTestCase.php

示例11: register

 /**
  * Register the Illuminate Database service
  *
  * @param Silex\Application $app
  */
 public function register(Application $app)
 {
     $app['database'] = $app->share(function () use($app) {
         $capsule = new Capsule();
         $capsule->addConnection($app['database.connection']);
         $capsule->setEventDispatcher(new Dispatcher(new Container()));
         if (isset($app['database.connection']['logging']) && $app['database.connection']['logging'] === true) {
             $capsule->getConnection()->enableQueryLog();
         }
         $capsule->setAsGlobal();
         $capsule->bootEloquent();
         return $capsule;
     });
 }
开发者ID:pinodex,项目名称:boardy,代码行数:19,代码来源:IlluminateDatabaseServiceProvider.php

示例12: connect

 /**
  * Start up eloquent
  *
  * @param array|null $credentials
  *
  * @return \Illuminate\Database\Connection|null
  */
 public function connect(array $credentials = null)
 {
     if ($credentials = $credentials ?? $this->getDsn()) {
         $this->capsule->getDatabaseManager()->purge($this->capsule->getDatabaseManager()->getDefaultConnection());
         $this->capsule->addConnection(array_merge(['driver' => 'mysql', 'host' => 'localhost', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => ''], $credentials));
         $this->capsule->setEventDispatcher($this->dispatcher);
         $this->capsule->setAsGlobal();
         $this->capsule->bootEloquent();
         $this->connection = $this->capsule->getConnection();
         $this->connection->enableQueryLog();
         return $this->connection;
     }
     return null;
 }
开发者ID:minutephp,项目名称:framework,代码行数:21,代码来源:Database.php

示例13: connect_db

 public function connect_db()
 {
     $localPDO = \DB::getPDO();
     $capsule = new Capsule();
     $capsule->addConnection($this->_DB, 'remote');
     $connection = $capsule->getConnection('remote');
     $remotePDO = $connection->getPdo();
     $class = '\\CODOF\\Importer\\Drivers\\' . $this->importer;
     $this->fetch = new $class($remotePDO);
     $this->connected = true;
     //\CODOF\DB::$connected ? true : false;
     $this->fetch->max_rows = $this->max_rows;
     $this->fetch->set_prefix($this->_DB['prefix']);
     $this->im = new Import($localPDO, $this->fetch);
 }
开发者ID:kertkulp,项目名称:php-ruhmatoo-projekt,代码行数:15,代码来源:ImportWorker.php

示例14: databaseHandler

 protected function databaseHandler()
 {
     $Database = new Manager();
     $config = $this->config['connection'];
     $Database->addConnection($config);
     $Connection = $Database->getConnection('default');
     $Schema = $Connection->getSchemaBuilder();
     if (!$Schema->hasTable($this->config['table'])) {
         $Schema->create($this->config['table'], function ($Table) {
             $Table->string('id')->unique();
             $Table->text('payload');
             $Table->integer('last_activity');
         });
     }
     return new DatabaseSessionHandler($Connection, $this->config['table']);
 }
开发者ID:laraport,项目名称:session,代码行数:16,代码来源:Session.php

示例15: register

 /**
  * Register Illuminate with the application
  *
  * @param array $config
  * @param Application $app
  * @return void
  */
 public function register(Application $app)
 {
     // Set some sane defaults
     $defaults = array('boot' => true, 'eloquent' => true, 'fetch' => PDO::FETCH_CLASS, 'global' => true, 'default' => 'default', 'connections' => array('default' => array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'silex', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => null)));
     // Merge in any passed configuration
     $this->config = array_merge($defaults, $app['db.config']);
     // Make sure all connections have all required fields
     if (isset($this->config['connections'])) {
         foreach ($this->config['connections'] as $index => $connection) {
             $this->config['connections'][$index] = array_merge($defaults['connections']['default'], $connection);
         }
     }
     // Create a container for the database pool
     $app['db.container'] = $app->share(function () {
         return new Container();
     });
     // Create the connections to the datbase
     $app['db'] = $app->share(function () use($app) {
         $db = new Capsule($app['db.container']);
         // Set PDO fetch mode as per configuration
         $db->setFetchMode($this->config['fetch']);
         // Set as global, use eloquent as per configuration
         if ($this->config['eloquent']) {
             $db->bootEloquent();
         }
         if ($this->config['global']) {
             $db->setAsGlobal();
         }
         // Set up the event dispatcher if we have it available
         if (class_exists('Illuminate\\Events\\Dispatcher')) {
             $db->setEventDispatcher(new Dispatcher($app['db.container']));
         }
         // Initialise each connection
         foreach ($this->config['connections'] as $connection => $options) {
             $db->addConnection(array_replace($this->config['connections'][$this->config['default']], $options), $connection);
             // If we're in debug mode we're going to want to use the query log, otherwise leave it disabled
             // to speed up queries and reduce memory usage
             if ($app['debug']) {
                 $db->getConnection($connection)->enableQueryLog();
             }
         }
         // Finally set default connection
         $db->getDatabaseManager()->setDefaultConnection($this->config['default']);
         return $db;
     });
 }
开发者ID:sjdaws,项目名称:silluminate,代码行数:53,代码来源:DatabaseServiceProvider.php


注:本文中的Illuminate\Database\Capsule\Manager::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。