本文整理汇总了PHP中Illuminate\Database\Query\Builder::getBindings方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::getBindings方法的具体用法?PHP Builder::getBindings怎么用?PHP Builder::getBindings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::getBindings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getArrayFromQuery
/**
* Is used for quick selecting of big number of records from database without creating ORM objects
* @param \Illuminate\Database\Query\Builder $query - Query Builder object
* @return array $results - results of query
*/
private static function getArrayFromQuery($query)
{
$sql = $query->toSql();
foreach ($query->getBindings() as $binding) {
$value = is_numeric($binding) ? $binding : "'" . $binding . "'";
$sql = preg_replace('/\\?/', $value, $sql, 1);
}
$results = \DB::select($sql);
return $results;
}
示例2: vsprintf
/**
* Render query SQL string.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @param \Illuminate\Database\Query\Builder $query
* @return string
*/
function render_sql(\Illuminate\Database\Query\Builder $query)
{
return vsprintf($query->toSql(), $query->getBindings());
}
示例3: toSql
public static function toSql(Builder $query)
{
$sql = $query->toSql();
$connection = $query->getConnection();
$pdo = $connection->getPdo();
$bindings = $query->getBindings();
$bindings = $connection->prepareBindings($bindings);
if (!empty($bindings)) {
foreach ($bindings as $binding) {
$sql = preg_replace('/\\?/', $pdo->quote($binding), $sql, 1);
}
}
return $sql;
}
示例4: getBindings
/**
* Get the current query value bindings in a flattened array.
*
* @return array
* @static
*/
public static function getBindings()
{
return \Illuminate\Database\Query\Builder::getBindings();
}
示例5: whereInExistingQuery
/**
* Add a external sub-select to the query.
*
* @param string $column
* @param \Illuminate\Database\Query\Builder|static $query
* @param string $boolean
* @param bool $not
* @return $this
*/
protected function whereInExistingQuery($column, $query, $boolean, $not)
{
$type = $not ? 'NotInSub' : 'InSub';
$this->wheres[] = compact('type', 'column', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
示例6: addWhereExistsQuery
/**
* Add an exists clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $boolean
* @param bool $not
* @return $this
*/
public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
示例7: addNestedWhereQuery
/**
* Add another query builder as a nested where to the query builder.
*
* @param \Illuminate\Database\Query\Builder|static $query
* @param string $boolean
* @return $this
*/
public function addNestedWhereQuery($query, $boolean = 'and')
{
if (count($query->wheres)) {
$type = 'Nested';
$this->wheres[] = compact('type', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
}
return $this;
}
示例8: whereCountQuery
/**
* Add a sub query count clause to the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $operator
* @param int $count
* @param string $boolean
* @return $this
*/
protected function whereCountQuery(QueryBuilder $query, $operator = '>=', $count = 1, $boolean = 'and')
{
if (is_numeric($count)) {
$count = new Expression($count);
}
$this->query->addBinding($query->getBindings(), 'where');
return $this->where(new Expression('(' . $query->toSql() . ')'), $operator, $count, $boolean);
}
示例9: performCountQuery
/**
* Performs the count query and returns info about the pages
*
* @param \Illuminate\Database\Query\Builder $countQuery
* @param string $querySql
* @param int $page
*
* @return array
*/
public function performCountQuery(QueryBuilder $countQuery, $querySql, $page)
{
//grab the model instance
$model = $this->config->getDataModel();
//then wrap the inner table and perform the count
$sql = "SELECT COUNT({$model->getKeyName()}) AS aggregate FROM ({$querySql}) AS agg";
//then perform the count query
$results = $countQuery->getConnection()->select($sql, $countQuery->getBindings());
$numRows = $results[0]->aggregate;
$page = (int) $page;
$last = (int) ceil($numRows / $this->rowsPerPage);
return array('page' => $page > $last ? $last : $page, 'last' => $last, 'total' => $numRows);
}
示例10: getQueryKey
protected function getQueryKey(Builder $builder, $other = null)
{
$name = $builder->getConnection()->getName();
return md5($name . $builder->toSql() . serialize($builder->getBindings()) . $other);
}
示例11: whereSubQuery
/**
* Add a full sub-select to the query.
*
* @param string $column
* @param \Illuminate\Database\Query\Builder $query
* @param string $boolean
* @return $this
*/
public function whereSubQuery($column, $query, $boolean = 'and')
{
list($type, $operator) = ['Sub', 'in'];
$this->wheres[] = compact('type', 'column', 'operator', 'query', 'boolean');
$this->addBinding($query->getBindings(), 'where');
return $this;
}
示例12: getConditionStringFromQueryBuilder
/**
* Extracts a raw WHERE clause string from a QueryBuilder instance.
* Note that this is practically identical to the original Listify.
*
* @param QueryBuilder $query A Query Builder instance
* @return string
*/
protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
{
$initialQueryChunks = explode('where ', $query->toSql());
if (count($initialQueryChunks) == 1) {
throw new InvalidArgumentException('The query builder instance must have a where clause to build a condition string from');
}
$queryChunks = explode('?', $initialQueryChunks[1]);
$chunkCount = count($queryChunks);
$bindings = $query->getBindings();
$whereString = '';
for ($i = 0; $i < $chunkCount; $i++) {
$whereString .= $queryChunks[$i];
if (isset($bindings[$i])) {
if (gettype($bindings[$i]) === 'string') {
$whereString .= '"' . $bindings[$i] . '"';
}
}
}
return $whereString;
}
示例13: toSql
/**
* Return sql statement
*
* @param Builder $queryBuilder
* @return string
*/
public static function toSql(Builder $queryBuilder)
{
$params = $queryBuilder->getBindings();
$pdoStatement = $queryBuilder->toSql();
foreach ($params as $param) {
$param = is_int($param) ? $param : "'{$param}'";
$pdoStatement = str_replace_first('?', $param, $pdoStatement);
}
return str_replace('`', '', $pdoStatement);
}
示例14: generateQueryHashFromQueryBuilder
/**
* @param Builder $qb
* @param array $attributes
*/
private function generateQueryHashFromQueryBuilder(Builder $qb, array $attributes)
{
$this->actualQueryHash = sha1(implode('_', [$this->cacheHashKeyPrefix, $qb->toSql(), serialize($qb->getBindings()), serialize($attributes)]));
}
示例15: scopeToSubQuery
/**
* @param EloquentBuilder|QueryBuilder|Model $query
* @param string $key
* @param bool $returnExpression
*
* @return string
*/
public function scopeToSubQuery($query, $key, $returnExpression = false)
{
$index = 0;
$bindings = array();
if (!Str::contains($key, '.')) {
/** @var Model|BetterEloquentTrait $model */
$model = $query->getModel();
$key = $model->getField($key);
}
$sql = $query->select(array($key))->toSql();
foreach ($query->getBindings() as $binding) {
$bindings[] = is_array($binding) ? array_merge($bindings, $binding) : $binding;
}
while (Str::contains($sql, '?')) {
$sql = $this->replaceFirst('?', $bindings[$index++], $sql);
}
$sql = "({$sql})";
return $returnExpression ? new Expression($sql) : $sql;
}