本文整理汇总了PHP中Illuminate\Database\DatabaseManager::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseManager::connection方法的具体用法?PHP DatabaseManager::connection怎么用?PHP DatabaseManager::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateSecondaryIndex
public function testCreateSecondaryIndex()
{
$cluster = new \CouchbaseCluster('127.0.0.1');
$clusterManager = $cluster->manager('Administrator', 'Administrator');
$clusterManager->createBucket($this->bucket, ['bucketType' => 'couchbase', 'saslPassword' => '', 'flushEnabled' => true]);
sleep(5);
/** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */
$connection = $this->databaseManager->connection('couchbase');
$bucket = $connection->openBucket($this->bucket);
$bucket->manager()->createN1qlPrimaryIndex();
sleep(4);
$output = new \Symfony\Component\Console\Output\BufferedOutput();
$this->command->run(new \Symfony\Component\Console\Input\ArrayInput(['bucket' => $this->bucket, 'name' => 'testing_gsi', 'fields' => ['params1', 'params2']]), $output);
$fetch = $output->fetch();
$this->assertSame("created SECONDARY INDEX [testing_gsi] fields [params1,params2], for [index_testing] bucket.", trim($fetch));
/** @var \Ytake\LaravelCouchbase\Database\CouchbaseConnection $connection */
$connection = $this->databaseManager->connection('couchbase');
$bucket = $connection->openBucket($this->bucket);
$indexes = $bucket->manager()->listN1qlIndexes();
foreach ($indexes as $index) {
if (!$index->isPrimary && $index->keyspace === 'keyspace') {
$this->assertSame("testing_gsi", $index->name);
$this->assertInstanceOf('CouchbaseN1qlIndex', $index);
}
}
$bucket->manager()->dropN1qlPrimaryIndex();
$bucket->manager()->dropN1qlIndex('testing_gsi');
$clusterManager->removeBucket($this->bucket);
}
示例2: invoke
/**
* @param MethodInvocation $invocation
*
* @return object
* @throws \Exception
*/
public function invoke(MethodInvocation $invocation)
{
/** @var \Illuminate\Database\ConnectionInterface $database */
$annotation = $invocation->getMethod()->getAnnotation($this->annotation);
$connection = $annotation->value;
$database = self::$databaseManager->connection($connection);
$database->beginTransaction();
try {
$result = $invocation->proceed();
$database->commit();
} catch (\Exception $exception) {
// for default Exception
if ($exception instanceof QueryException) {
$database->rollBack();
throw $exception;
}
if ($exception instanceof $annotation->expect) {
$database->rollBack();
throw $exception;
}
$database->rollBack();
throw $exception;
}
return $result;
}
示例3: fire
/**
* Execute the console command
*/
public function fire()
{
/** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */
$connection = $this->databaseManager->connection($this->option('database'));
if ($connection instanceof CouchbaseConnection) {
$bucket = $connection->openBucket($this->argument('bucket'));
$primary = self::PRIMARY_KEY;
try {
$bucket->manager()->createN1qlPrimaryIndex($primary, $this->option('ignore'), $this->option('defer'));
$this->info("created PRIMARY INDEX [{$primary}] for [{$this->argument('bucket')}] bucket.");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
foreach ($this->secondaryIndexes as $name => $fields) {
try {
$bucket->manager()->createN1qlIndex($name, $fields, '', $this->option('ignore'), $this->option('defer'));
$field = implode(",", $fields);
$this->info("created SECONDARY INDEX [{$name}] fields [{$field}], for [{$this->argument('bucket')}] bucket.");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
}
return;
}
示例4: __construct
/**
* Builder constructor.
* @param DatabaseManager $databaseManager
* @param AppConfig $appConfig
*/
public function __construct(DatabaseManager $databaseManager, AppConfig $appConfig)
{
$this->manager = $databaseManager->connection()->getDoctrineSchemaManager();
$this->appConfig = $appConfig;
$this->tablePrefix = $databaseManager->connection() - getTablePrefix();
$this->registerUserTypes();
}
示例5: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->init();
$this->app->singleton('Larapress\\Services\\Helpers', function () {
return new Helpers($this->app['config'], $this->app['translator'], $this->app['view'], $this->app['Larapress\\Interfaces\\MockablyInterface'], $this->app->make('log')->getMonolog(), $this->app['request'], $this->app['session.store'], $this->db->connection($this->defaultDbConnection), $this->app['redirect'], $this->app['Illuminate\\Support\\Facades\\Response'], $this->app['app'], $this->app['Carbon\\Carbon']);
});
}
示例6: __construct
public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, Translator $Lang)
{
$this->DB = $DB;
$this->AuthenticationManager = $AuthenticationManager;
/*
$this->Database = $DB->table('ACCT_Journal_Entry AS je')
->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')
->rightJoin('ACCT_Account AS c', 'je.account_id', '=', 'c.id')
->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')
->where(function($query)
{
$query->orWhere('jv.status', '=', 'B');
$query->orWhereNull('jv.status');
}
)
->where('c.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())
->whereIn('at.pl_bs_category', array('B', 'C'))
->whereNull('je.deleted_at')
->whereNull('jv.deleted_at');
*/
$this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->rightJoin('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')->where('jv.status', '=', 'B')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereIn('at.pl_bs_category', array('B', 'C'))->whereNull('je.deleted_at')->whereNull('jv.deleted_at');
$this->Database2 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Account AS c')->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')->where('c.is_group', '=', 1)->where('c.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->whereIn('at.pl_bs_category', array('B', 'C'))->select(array($DB->raw('0 AS acct_pl_debit'), $DB->raw('0 AS acct_pl_credit'), 'c.id AS acct_pl_account_id', 'c.parent_account_id AS acct_pl_parent_account_id', 'c.key AS acct_pl_account_key', 'c.name AS acct_pl_account_name', 'c.is_group AS acct_pl_is_group', 'c.balance_type AS acct_pl_balance_type', $DB->raw('CASE at.pl_bs_category WHEN "B" THEN "' . $Lang->get('decima-accounting::profit-and-loss.income') . '" ELSE "' . $Lang->get('decima-accounting::profit-and-loss.expenses') . '" END AS acct_pl_pl_bs_category'), $DB->raw('0 AS acct_pl_balance')));
$this->visibleColumns = array($DB->raw('IFNULL(SUM(je.debit),0) AS acct_pl_debit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_pl_credit'), 'c.id AS acct_pl_account_id', 'c.parent_account_id AS acct_pl_parent_account_id', 'c.key AS acct_pl_account_key', 'c.name AS acct_pl_account_name', 'c.is_group AS acct_pl_is_group', 'c.balance_type AS acct_pl_balance_type', $DB->raw('CASE at.pl_bs_category WHEN "B" THEN "' . $Lang->get('decima-accounting::profit-and-loss.income') . '" ELSE "' . $Lang->get('decima-accounting::profit-and-loss.expenses') . '" END AS acct_pl_pl_bs_category'), $DB->raw('0 AS acct_pl_balance'));
$this->orderBy = array(array('acct_pl_account_key', 'asc'));
}
示例7: process
/**
* @inheritdoc
*/
public function process(EloquentModel $model, Config $config)
{
$schemaManager = $this->databaseManager->connection()->getDoctrineSchemaManager();
$prefix = $this->databaseManager->connection()->getTablePrefix();
if (!$schemaManager->tablesExist($prefix . $model->getTableName())) {
throw new GeneratorException(sprintf('Table %s does not exist', $prefix . $model->getTableName()));
}
}
示例8: fire
/**
* fire.
*
* @method fire
*/
public function fire()
{
$connection = $this->databaseManager->connection();
$connection->setFetchMode(PDO::FETCH_ASSOC);
$query = $this->option('command');
$rows = $connection->select($query);
$headers = array_keys(Arr::get($rows, 0, []));
$this->table($headers, $rows);
}
示例9: tables
/**
* Return a description for each table.
*
* @return \Generator
*/
public function tables()
{
$schema = $this->db->connection()->getDoctrineConnection()->getSchemaManager();
$tables = $schema->listTableNames();
foreach ($tables as $table) {
$columns = $this->describer->describe($table);
(yield compact('table', 'columns'));
}
}
示例10: run
public function run()
{
if ($this->truncate) {
$this->db->connection()->table($this->getTableName())->truncate();
}
foreach ($this->seeds as $seed) {
$this->getModelInstance()->create($seed);
}
}
示例11: fire
/**
* Execute the console command
*/
public function fire()
{
/** @var \Illuminate\Database\Connection|CouchbaseConnection $connection */
$connection = $this->databaseManager->connection($this->option('database'));
if ($connection instanceof CouchbaseConnection) {
$bucket = $connection->openBucket($this->argument('bucket'));
$bucket->manager()->dropN1qlPrimaryIndex($this->option('name'), $this->option('ignore'));
$this->info("dropped PRIMARY INDEX [{$this->option('name')}] for [{$this->argument('bucket')}] bucket.");
}
return;
}
示例12: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$connection = $this->argument('connection');
$name = $this->database->connection($connection)->getDatabaseName();
try {
$this->database->connection($connection)->reconnect();
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
$this->info(sprintf('Connected with database "%s" through connection "%s"', $name, $connection));
}
示例13: __construct
public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, AccountManagementInterface $AccountManager, Translator $Lang, Carbon $Carbon)
{
$this->DB = $DB;
$this->AccountManager = $AccountManager;
$this->AuthenticationManager = $AuthenticationManager;
$this->Carbon = $Carbon;
$this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array($DB->raw('IFNULL(SUM(je.debit),0) AS acct_gl_debit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_gl_credit'), 'c.id AS acct_gl_account_id', 'c.parent_account_id AS acct_gl_parent_account_id', 'c.key AS acct_gl_account_key', 'c.name AS acct_gl_account_name', 'c.is_group AS acct_gl_is_group', 'c.balance_type AS acct_gl_balance_type', $DB->raw('0 AS acct_gl_total_debit'), $DB->raw('0 AS acct_gl_total_credit'), $DB->raw('0 AS acct_gl_opening_balance'), $DB->raw('0 AS acct_gl_closing_balance'), $DB->raw('\'\' AS acct_gl_voucher_date'), $DB->raw('\'\' AS acct_gl_voucher_type'), $DB->raw('\'\' AS acct_gl_voucher_number')));
$this->Database2 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Account AS c')->where('c.is_group', '=', 1)->where('c.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->select(array($DB->raw('0 AS acct_gl_debit'), $DB->raw('0 AS acct_gl_credit'), 'c.id AS acct_gl_account_id', 'c.parent_account_id AS acct_gl_parent_account_id', 'c.key AS acct_gl_account_key', 'c.name AS acct_gl_account_name', 'c.is_group AS acct_gl_is_group', 'c.balance_type AS acct_gl_balance_type', $DB->raw('0 AS acct_gl_total_debit'), $DB->raw('0 AS acct_gl_total_credit'), $DB->raw('0 AS acct_gl_opening_balance'), $DB->raw('0 AS acct_gl_closing_balance'), $DB->raw('\'\' AS acct_gl_voucher_date'), $DB->raw('\'\' AS acct_gl_voucher_type'), $DB->raw('\'\' AS acct_gl_voucher_number')));
$this->Database3 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array($DB->raw('0 AS acct_gl_debit'), $DB->raw('0 AS acct_gl_credit'), 'c.id AS acct_gl_account_id', 'c.parent_account_id AS acct_gl_parent_account_id', 'c.key AS acct_gl_account_key', 'c.name AS acct_gl_account_name', 'c.is_group AS acct_gl_is_group', 'c.balance_type AS acct_gl_balance_type', $DB->raw('IFNULL(SUM(je.debit),0) AS acct_gl_total_credit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_gl_total_credit'), $DB->raw('0 AS acct_gl_opening_balance'), $DB->raw('0 AS acct_gl_closing_balance'), $DB->raw('\'\' AS acct_gl_voucher_date'), $DB->raw('\'\' AS acct_gl_voucher_type'), $DB->raw('\'\' AS acct_gl_voucher_number')));
$this->Database4 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->join('ACCT_Voucher_Type AS vt', 'vt.id', '=', 'jv.voucher_type_id')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array($DB->raw('je.debit AS acct_gl_debit'), $DB->raw('je.credit AS acct_gl_credit'), 'c.id AS acct_gl_account_id', 'c.parent_account_id AS acct_gl_parent_account_id', $DB->raw('IFNULL(jv.manual_reference,"' . $Lang->get('decima-accounting::journal-management.noRef') . '") AS acct_gl_account_key'), 'jv.remark AS acct_gl_account_name', 'c.is_group AS acct_gl_is_group', 'c.balance_type AS acct_gl_balance_type', $DB->raw('0 AS acct_gl_total_debit'), $DB->raw('0 AS acct_gl_total_credit'), $DB->raw('0 AS acct_gl_opening_balance'), $DB->raw('0 AS acct_gl_closing_balance'), $DB->raw('DATE_FORMAT(jv.date, "' . $Lang->get('form.mysqlDateFormat') . '") AS acct_gl_voucher_date'), $DB->raw('vt.name AS acct_gl_voucher_type'), $DB->raw('jv.number AS acct_gl_voucher_number')));
$this->orderBy = array(array('acct_gl_account_key', 'asc'));
}
示例14: __construct
public function __construct(DatabaseManager $DB, AuthenticationManagementInterface $AuthenticationManager, Translator $Lang, Carbon $Carbon)
{
$this->DB = $DB;
$this->AuthenticationManager = $AuthenticationManager;
$this->Carbon = $Carbon;
$this->Database = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array($DB->raw('IFNULL(SUM(je.debit),0) AS acct_tb_debit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_tb_credit'), 'c.id AS acct_tb_account_id', 'c.parent_account_id AS acct_tb_parent_account_id', 'c.key AS acct_tb_account_key', 'c.name AS acct_tb_account_name', 'c.is_group AS acct_tb_is_group', 'c.balance_type AS acct_tb_balance_type', $DB->raw('0 AS acct_tb_total_debit'), $DB->raw('0 AS acct_tb_total_credit'), $DB->raw('0 AS acct_tb_opening_balance'), $DB->raw('0 AS acct_tb_closing_balance')));
$this->Database2 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Account AS c')->where('c.is_group', '=', 1)->where('c.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->select(array($DB->raw('0 AS acct_tb_debit'), $DB->raw('0 AS acct_tb_credit'), 'c.id AS acct_tb_account_id', 'c.parent_account_id AS acct_tb_parent_account_id', 'c.key AS acct_tb_account_key', 'c.name AS acct_tb_account_name', 'c.is_group AS acct_tb_is_group', 'c.balance_type AS acct_tb_balance_type', $DB->raw('0 AS acct_tb_total_debit'), $DB->raw('0 AS acct_tb_total_credit'), $DB->raw('0 AS acct_tb_opening_balance'), $DB->raw('0 AS acct_tb_closing_balance')));
$this->Database3 = $DB->connection($AuthenticationManager->getCurrentUserOrganizationConnection())->table('ACCT_Journal_Entry AS je')->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')->where('jv.organization_id', '=', $AuthenticationManager->getCurrentUserOrganizationId())->where('c.is_group', '=', 0)->whereNull('je.deleted_at')->whereNull('jv.deleted_at')->select(array($DB->raw('0 AS acct_tb_debit'), $DB->raw('0 AS acct_tb_credit'), 'c.id AS acct_tb_account_id', 'c.parent_account_id AS acct_tb_parent_account_id', 'c.key AS acct_tb_account_key', 'c.name AS acct_tb_account_name', 'c.is_group AS acct_tb_is_group', 'c.balance_type AS acct_tb_balance_type', $DB->raw('IFNULL(SUM(je.debit),0) acct_tb_total_debit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_tb_total_credit'), $DB->raw('0 AS acct_tb_opening_balance'), $DB->raw('0 AS acct_tb_closing_balance')));
// $this->visibleColumns = array($DB->raw('IFNULL(SUM(je.debit),0) AS acct_tb_debit'), $DB->raw('IFNULL(SUM(je.credit),0) AS acct_tb_credit'),
// 'c.id AS acct_tb_account_id', 'c.parent_account_id AS acct_tb_parent_account_id','c.key AS acct_tb_account_key', 'c.name AS acct_tb_account_name', 'c.is_group AS acct_tb_is_group', 'c.balance_type AS acct_tb_balance_type',
// $DB->raw('0 AS acct_tb_total_debit'), $DB->raw('0 AS acct_tb_total_credit'), $DB->raw('0 AS acct_tb_opening_balance'), $DB->raw('0 AS acct_tb_closing_balance'),
// );
$this->orderBy = array(array('acct_tb_account_key', 'asc'));
}
示例15: process
/**
* @inheritdoc
*/
public function process(EloquentModel $model, Config $config)
{
$schemaManager = $this->databaseManager->connection()->getDoctrineSchemaManager();
$prefix = $this->databaseManager->connection()->getTablePrefix();
$foreignKeys = $schemaManager->listTableForeignKeys($prefix . $model->getTableName());
foreach ($foreignKeys as $tableForeignKey) {
$tableForeignColumns = $tableForeignKey->getForeignColumns();
if (count($tableForeignColumns) !== 1) {
continue;
}
$relation = new BelongsTo($this->removePrefix($prefix, $tableForeignKey->getForeignTableName()), $tableForeignKey->getLocalColumns()[0], $tableForeignColumns[0]);
$this->addRelation($model, $relation);
}
$tables = $schemaManager->listTables();
foreach ($tables as $table) {
if ($table->getName() === $prefix . $model->getTableName()) {
continue;
}
$foreignKeys = $table->getForeignKeys();
foreach ($foreignKeys as $name => $foreignKey) {
if ($foreignKey->getForeignTableName() === $prefix . $model->getTableName()) {
$localColumns = $foreignKey->getLocalColumns();
if (count($localColumns) !== 1) {
continue;
}
if (count($foreignKeys) === 2 && count($table->getColumns()) === 2) {
$keys = array_keys($foreignKeys);
$key = array_search($name, $keys) === 0 ? 1 : 0;
$secondForeignKey = $foreignKeys[$keys[$key]];
$secondForeignTable = $this->removePrefix($prefix, $secondForeignKey->getForeignTableName());
$relation = new BelongsToMany($secondForeignTable, $this->removePrefix($prefix, $table->getName()), $localColumns[0], $secondForeignKey->getLocalColumns()[0]);
$this->addRelation($model, $relation);
break;
} else {
$tableName = $this->removePrefix($prefix, $foreignKey->getLocalTableName());
$foreignColumn = $localColumns[0];
$localColumn = $foreignKey->getForeignColumns()[0];
if ($this->isColumnUnique($table, $foreignColumn)) {
$relation = new HasOne($tableName, $foreignColumn, $localColumn);
} else {
$relation = new HasMany($tableName, $foreignColumn, $localColumn);
}
$this->addRelation($model, $relation);
}
}
}
}
}