本文整理汇总了PHP中Illuminate\Database\Query\Builder::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::getConnection方法的具体用法?PHP Builder::getConnection怎么用?PHP Builder::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$results = $query->getConnection()->selectFromWriteConnection($sql, $values);
$sequence = $sequence ?: 'id';
$result = (array) $results[0];
$id = $result[$sequence];
return is_numeric($id) ? (int) $id : $id;
}
示例2: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$results = $query->getConnection()->select($sql, $values);
$sequence = $sequence ?: 'id';
$result = (array) $results[0];
return (int) $result[$sequence];
}
示例3: __construct
/**
* Create a new join clause instance.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return void
*/
public function __construct(Builder $parentQuery, $type, $table)
{
$this->type = $type;
$this->table = $table;
$this->parentQuery = $parentQuery;
parent::__construct($parentQuery->getConnection(), $parentQuery->getGrammar(), $parentQuery->getProcessor());
}
示例4: count
/**
* Get rows count
*
* @return int
*/
public function count()
{
$connection = $this->query->getConnection();
$myQuery = clone $this->query;
// if its a normal query ( no union, having and distinct word )
// replace the select with static text to improve performance
if (!Str::contains(Str::lower($myQuery->toSql()), ['union', 'having', 'distinct', 'order by', 'group by'])) {
$row_count = $connection->getQueryGrammar()->wrap('row_count');
$myQuery->select($connection->raw("'1' as {$row_count}"));
}
return $connection->table($connection->raw('(' . $myQuery->toSql() . ') count_row_table'))->setBindings($myQuery->getBindings())->count();
}
示例5: fields
/**
* @param array $fields
* @return array
*/
public function fields($fields = [])
{
if (empty($fields)) {
$conn = $this->operator->getConnection();
if ($conn->getName() == 'mysql') {
$results = $conn->select((new \Illuminate\Database\Schema\Grammars\MySqlGrammar())->compileColumnExists(), [$conn->getDatabaseName(), $conn->getTablePrefix() . $this->table]);
$this->_fields = array_map(function ($v) {
return is_array($v) ? $v['column_name'] : $v->column_name;
}, $results);
}
}
return $this->_fields;
}
示例6: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$result = $query->getConnection()->selectFromWriteConnection($sql, $values)[0];
$sequence = $sequence ?: 'id';
$id = is_object($result) ? $result->{$sequence} : $result[$sequence];
return is_numeric($id) ? (int) $id : $id;
}
示例7: prepareStatement
/**
* Get prepared statement.
*
* @param Builder $query
* @param string $sql
* @return \PDOStatement|\Yajra\Pdo\Oci8
*/
private function prepareStatement(Builder $query, $sql)
{
/** @var \Yajra\Oci8\Oci8Connection $connection */
$connection = $query->getConnection();
$pdo = $connection->getPdo();
return $pdo->prepare($sql);
}
示例8: parseFullTextSearch
/**
* Parse the fulltext search parameter q
*
* @param string $qParam
* @param array $fullTextSearchColumns
* @return void
*/
protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
{
if ($qParam == '') {
//Add where that will never be true
$this->query->whereRaw('0 = 1');
return;
}
$fulltextType = Config::get('apihandler.fulltext');
if ($fulltextType == 'native') {
//Use pdo's quote method to be protected against sql-injections.
//The usual placeholders unfortunately don't seem to work using AGAINST().
$qParam = $this->query->getConnection()->getPdo()->quote($qParam);
//Use native fulltext search
$this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
//Add the * to the selects because of the score column
if (count($this->query->columns) == 0) {
$this->query->addSelect('*');
}
//Add the score column
$scoreColumn = Config::get('apihandler.fulltext_score_column');
$this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
} else {
$keywords = explode(' ', $qParam);
//Use default php implementation
$this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
foreach ($fullTextSearchColumns as $column) {
foreach ($keywords as $keyword) {
$query->orWhere($column, 'LIKE', '%' . $keyword . '%');
}
}
});
}
}
示例9: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$query->getConnection()->insert($sql, $values);
try {
$id = $query->getConnection()->getPdo()->lastInsertId();
} catch (\PDOException $e) {
if ($e->getCode() == 'IM001') {
$sth = $query->getConnection()->getPdo()->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int)");
$sth->execute();
$result = $sth->fetch();
$id = $result[0];
} else {
throw $e;
}
}
return is_numeric($id) ? (int) $id : $id;
}
示例10: simplePaginate
/**
* Get a paginator only supporting simple next and previous links.
*
* This is more efficient on larger data-sets, etc.
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = array('*'))
{
$paginator = $this->query->getConnection()->getPaginator();
$page = $paginator->getCurrentPage();
$perPage = $perPage ?: $this->model->getPerPage();
$this->query->skip(($page - 1) * $perPage)->take($perPage + 1);
return $paginator->make($this->get($columns)->all(), $perPage);
}
示例11: firstOrCreate
/**
* Get the first record matching the attributes or create it.
*
* @param array $attributes
* @param array $values
* @return \Illuminate\Database\Eloquent\Model
*/
public function firstOrCreate(array $attributes, array $values = [])
{
if (!is_null($instance = $this->where($attributes)->first())) {
return $instance;
}
$instance = $this->model->newInstance($attributes + $values)->setConnection($this->query->getConnection()->getName());
$instance->save();
return $instance;
}
示例12: paginate
/**
* Get a paginator for the "select" statement.
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Pagination\Paginator
*/
public function paginate($perPage = null, $columns = array('*'))
{
$perPage = $perPage ?: $this->model->getPerPage();
$paginator = $this->query->getConnection()->getPaginator();
if (isset($this->query->groups)) {
return $this->groupedPaginate($paginator, $perPage, $columns);
} else {
return $this->ungroupedPaginate($paginator, $perPage, $columns);
}
}
示例13: __construct
/**
* EloquentManager constructor.
*
* @param Builder|\Eloquent $model
* @param Request $request
*/
public function __construct($model, Request $request)
{
$this->response = new DataTable();
$this->query = $model instanceof Builder ? $model : $model->getQuery();
$this->request = $request;
// $this->columns = $this->query->columns;
$this->connection = $model->getConnection();
$this->prefix = $this->connection->getTablePrefix();
$this->database = $this->connection->getDriverName();
}
示例14: processInsertGetId
/**
* Process an "insert get ID" query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $sql
* @param array $values
* @param string $sequence
* @return int
*/
public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
{
$connection = $query->getConnection();
$connection->insert($sql, $values);
if ($connection->getConfig('odbc') === true) {
$id = $this->processInsertGetIdForOdbc($connection);
} else {
$id = $connection->getPdo()->lastInsertId();
}
return is_numeric($id) ? (int) $id : $id;
}
示例15: init
/**
* Initialize attributes.
*
* @param \Yajra\Datatables\Request $request
* @param \Illuminate\Database\Query\Builder $builder
* @param string $type
*/
protected function init($request, $builder, $type = 'builder')
{
$this->request = $request;
$this->query_type = $type;
$this->columns = $builder->columns;
$this->connection = $builder->getConnection();
$this->prefix = $this->connection->getTablePrefix();
$this->database = $this->connection->getDriverName();
if ($this->isDebugging()) {
$this->connection->enableQueryLog();
}
}