本文整理汇总了PHP中Illuminate\Database\Connection类的典型用法代码示例。如果您正苦于以下问题:PHP Connection类的具体用法?PHP Connection怎么用?PHP Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compileRenameColumn
/**
* Compile a rename column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @return array
*/
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
{
$schema = $connection->getDoctrineSchemaManager();
$column = $connection->getDoctrineColumn($blueprint->getTable(), $command->from);
$tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema);
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
}
示例2: __construct
public function __construct(Connection $connection, RepositoryContract $config)
{
$dbconfig = $config->get('database.connections.' . $connection->getName());
$this->dsn = static::parseDSN($dbconfig);
$this->username = $dbconfig['username'];
$this->password = $dbconfig['password'];
}
示例3: __construct
public function __construct(\Illuminate\Database\Connection $connection)
{
if (!$connection->getSchemaGrammar()) {
$connection->useDefaultGrammar();
}
parent::__construct($connection);
}
示例4: addQuery
/**
*
* @param string $query
* @param array $bindings
* @param float $time
* @param \Illuminate\Database\Connection $connection
*/
public function addQuery($query, $bindings, $time, $connection)
{
$time = $time / 1000;
$endTime = microtime(true);
$startTime = $endTime - $time;
$pdo = $connection->getPdo();
$bindings = $connection->prepareBindings($bindings);
$bindings = $this->checkBindings($bindings);
if (!empty($bindings) && $this->renderSqlWithParams) {
foreach ($bindings as $binding) {
$query = preg_replace('/\\?/', $pdo->quote($binding), $query, 1);
}
}
$source = null;
if ($this->findSource) {
try {
$source = $this->findSource();
} catch (\Exception $e) {
}
}
$this->queries[] = array('query' => $query, 'bindings' => $bindings, 'time' => $time, 'source' => $source);
if ($this->timeCollector !== null) {
$this->timeCollector->addMeasure($query, $startTime, $endTime);
}
}
示例5: __construct
/**
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
$this->grammar = $connection->getSchemaGrammar();
$this->helper = new OracleAutoIncrementHelper($connection);
$this->comment = new Comment($connection);
}
示例6: addQuery
/**
*
* @param string $query
* @param array $bindings
* @param float $time
* @param \Illuminate\Database\Connection $connection
*/
public function addQuery($query, $bindings, $time, $connection)
{
$explainResults = array();
$time = $time / 1000;
$endTime = microtime(true);
$startTime = $endTime - $time;
$hints = $this->performQueryAnalysis($query);
$pdo = $connection->getPdo();
$bindings = $connection->prepareBindings($bindings);
// Run EXPLAIN on this query (if needed)
if ($this->explainQuery && preg_match('/^(' . implode($this->explainTypes) . ') /i', $query)) {
$statement = $pdo->prepare('EXPLAIN ' . $query);
$statement->execute($bindings);
$explainResults = $statement->fetchAll(\PDO::FETCH_CLASS);
}
$bindings = $this->checkBindings($bindings);
if (!empty($bindings) && $this->renderSqlWithParams) {
foreach ($bindings as $binding) {
$query = preg_replace('/\\?/', $pdo->quote($binding), $query, 1);
}
}
$source = null;
if ($this->findSource) {
try {
$source = $this->findSource();
} catch (\Exception $e) {
}
}
$this->queries[] = array('query' => $query, 'bindings' => $this->escapeBindings($bindings), 'time' => $time, 'source' => $source, 'explain' => $explainResults, 'hints' => $hints);
if ($this->timeCollector !== null) {
$this->timeCollector->addMeasure($query, $startTime, $endTime);
}
}
示例7: getSchemaBuilder
/**
* Retrieve the schema builder for the database connection. And set a custom blueprint resolver to return an
* instance of the Culpa Blueprint class.
*
* @param Connection $connection
* @return \Illuminate\Database\Schema\Builder
*/
protected static function getSchemaBuilder(Connection $connection)
{
$schemaBuilder = $connection->getSchemaBuilder();
$schemaBuilder->blueprintResolver(function ($table, $callback) {
return new Blueprint($table, $callback);
});
return $schemaBuilder;
}
示例8: processInsertGetIdForOdbc
/**
* Process an "insert get ID" query for ODBC.
*
* @param \Illuminate\Database\Connection $connection
* @return int
*/
protected function processInsertGetIdForOdbc($connection)
{
$result = $connection->select('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid');
if (!$result) {
throw new Exception('Unable to retrieve lastInsertID for ODBC.');
}
return $result[0]->insertid;
}
示例9: getNickId
/**
* @param \Illuminate\Database\Connection $db
* @param int $channelId
* @param string $nick
* @return int
*/
protected function getNickId(Connection $db, $channelId, $nick)
{
$targetNick = $db->table('nicks')->select('id')->where('channel_id', '=', $channelId)->where('nick', '=', $nick)->first();
if ($targetNick) {
return $targetNick['id'];
} else {
return $db->table('nicks')->insertGetId(['channel_id' => $channelId, 'nick' => $nick]);
}
}
示例10: processInsertGetIdForOdbc
/**
* Process an "insert get ID" query for ODBC.
*
* @param \Illuminate\Database\Connection $connection
* @return int
*/
protected function processInsertGetIdForOdbc($connection)
{
$result = $connection->selectFromWriteConnection('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) AS insertid');
if (!$result) {
throw new Exception('Unable to retrieve lastInsertID for ODBC.');
}
$row = $result[0];
return is_object($row) ? $row->insertid : $row['insertid'];
}
示例11: __construct
/**
* Create a new schema blueprint.
*
* @param string $table
* @param Closure $callback
*/
public function __construct(Connection $connection, $collection)
{
$this->connection = $connection;
try {
$this->collection = $connection->getCollection($collection);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
$this->collection = ['type' => $collection];
}
}
示例12: compileCreateEncoding
/**
* Append the character set specifications to a command.
*
* @param string $sql
* @param \Illuminate\Database\Connection $connection
* @return string
*/
protected function compileCreateEncoding($sql, Connection $connection)
{
if (!is_null($charset = $connection->getConfig('charset'))) {
$sql .= ' default character set ' . $charset;
}
if (!is_null($collation = $connection->getConfig('collation'))) {
$sql .= ' collate ' . $collation;
}
return $sql;
}
示例13: prepare
/**
* Prepare the database connection instance.
*
* @param Illuminate\Database\Connection $connection
* @return Illuminate\Database\Connection
*/
protected function prepare(Connection $connection)
{
$connection->setFetchMode($this->app['config']['database.fetch']);
$connection->setEventDispatcher($this->app['events']);
// We will setup a Closure to resolve the paginator instance on the connection
// since the Paginator isn't sued on every request and needs quite a few of
// our dependencies. It'll be more efficient to lazily resolve instances.
$app = $this->app;
$connection->setPaginator(function () use($app) {
return $app['paginator'];
});
return $connection;
}
示例14: compileCreateEncoding
/**
* Append the character set specifications to a command.
*
* @param string $sql
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @return string
*/
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
{
if (isset($blueprint->charset)) {
$sql .= ' default character set ' . $blueprint->charset;
} elseif (!is_null($charset = $connection->getConfig('charset'))) {
$sql .= ' default character set ' . $charset;
}
if (isset($blueprint->collation)) {
$sql .= ' collate ' . $blueprint->collation;
} elseif (!is_null($collation = $connection->getConfig('collation'))) {
$sql .= ' collate ' . $collation;
}
return $sql;
}
示例15: drop
/**
* function to safely drop trigger db object
*
* @param string $name
* @return boolean
*/
public function drop($name)
{
if (!$name) {
return false;
}
return $this->connection->statement("\n declare\n e exception;\n pragma exception_init(e,-4080);\n begin\n execute immediate 'drop trigger {$name}';\n exception\n when e then\n null;\n end;");
}