本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::execute方法的具体用法?PHP QueryBuilder::execute怎么用?PHP QueryBuilder::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Query\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* @return array
*/
public function fetch()
{
$data = $this->query->execute()->fetchAll(\PDO::FETCH_KEY_PAIR);
$keys = array_keys($data);
$this->query->setParameter(':lastId', array_pop($keys));
return array_values($data);
}
示例2: getResults
/**
* @param int $page Starts at 1
* @param bool $allResults
* @return DataObjectInterface[]
*/
public function getResults($page, $allResults = false)
{
if ($page < 1 || $page > $this->getPages()) {
throw new InvalidArgumentException("Page must be between 1 and {$this->getPages()}");
}
if (!$allResults) {
$this->page = $page;
$this->prev = $page > 1 ? $page - 1 : 0;
$this->next = $page < $this->pages ? $page + 1 : 0;
$this->qb->setMaxResults($this->pageSize)->setFirstResult(($page - 1) * $this->pageSize);
}
$statement = $this->qb->execute();
return $statement->fetchAll(\PDO::FETCH_CLASS, $this->class, $this->dependencies);
}
示例3: execute
public function execute()
{
foreach ($this->conditions as $field => $value) {
$this->setParameter(":{$field}", $value);
}
return parent::execute();
}
示例4: setUp
public function setUp()
{
$builder = new QueryBuilder(Connection::get());
$builder->select('*')->from('test_users');
$this->data = $builder->execute()->fetchAll(\PDO::FETCH_OBJ);
$this->operations = new OperationCollection();
$this->service = new DoctrineProcessingService(new DoctrineProcessorResolver(), $this->operations, $builder);
$this->totalCount = (new QueryBuilder(Connection::get()))->select('count(*)')->from('test_users')->execute()->fetchColumn();
self::assertTrue($this->totalCount > 0);
}
示例5: executeSelectQuery
/**
* @param QueryBuilder $query
* @return array
*/
protected function executeSelectQuery(QueryBuilder $query)
{
$rows = array();
$statement = $query->execute();
/** @todo Should configure which fetch method to use (fetch row by row or fetchAll) */
while (($row = $statement->fetch(PDO::FETCH_ASSOC)) !== false) {
$this->processRow($row, $rows);
}
$rows = $this->processRows($rows);
return $this->denormalizeRows($rows);
}
示例6: setDBALQuery
/**
* Prepare listing instance from Doctrine DBAL QueryBuilder.
*
* Total rows count for Listing instance must be set separately.
*
* @param DBALQueryBuilder
* @param boolean
* @param boolean
* @return self
*/
public function setDBALQuery(DBALQueryBuilder $query, $appendLimit = true, $appendOrder = true)
{
if ($appendLimit) {
$query->setFirstResult($this->offset())->setMaxResults($this->limit());
}
if ($appendOrder && $this->order()) {
call_user_func_array([$query, 'orderBy'], (array) $this->order());
}
$this->setItems($query->execute()->fetchAll());
return $this;
}
示例7: run
/**
* @return array
*/
protected function run()
{
if (!$this->result || $this->queryBuilder->getState() === QueryBuilder::STATE_DIRTY) {
$statement = $this->queryBuilder->execute();
$statement->setFetchMode(\PDO::FETCH_ASSOC);
$rows = $statement->fetchAll();
$statement->closeCursor();
$this->result = $this->mapper ? $this->mapper->collection($rows) : $rows;
}
return $this->result;
}
示例8: getFilteredPostsIds
protected function getFilteredPostsIds(array $identifiers, $mask, array $orX = [])
{
$qb = new QueryBuilder($this->connection);
$qb->select('p.id')->from('posts', 'p');
$aclFilter = new DoctrineDbalAclFilter($qb);
$aclFilter->setAclSchema($this->aclSchema);
$aclFilter->apply('p', 'id', 'post-', $identifiers, $mask, $orX);
$result = array_map(function ($post) {
return (int) $post['id'];
}, $qb->execute()->fetchAll());
return [$result];
}
示例9: loadRoles
/**
* Load roles at RBAC creation.
*
* @param Event $e
* @return array
*/
public function loadRoles(Event $e)
{
$builder = new QueryBuilder($this->connection);
$options = $this->options;
$builder->select("role.{$options->getNameColumn()} AS name, parent.{$options->getNameColumn()} AS parent")->from($options->getTable(), 'role')->leftJoin('role', $options->getTable(), 'parent', "role.{$options->getJoinColumn()} = parent.{$options->getIdColumn()}");
$result = $builder->execute();
$roles = array();
foreach ($result as $row) {
$parentName = isset($row['parent']) ? $row['parent'] : 0;
unset($row['parent']);
$roles[$parentName][] = $row['name'];
}
$this->recursiveRoles($e->getRbac(), $roles);
}
示例10: rewind
/**
* Rewind
*/
public function rewind()
{
//Only perform rewind if current item is not the first element
if ($this->currentKey !== 0) {
$this->batchPosition = 0;
$this->queryBuilder->setFirstResult(0);
$this->queryBuilder->setMaxResults($this->batchSize);
/* @var $stmt \Doctrine\DBAL\Statement */
$stmt = $this->queryBuilder->execute();
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$this->currentItem = null;
$this->currentKey = -1;
$this->statement = $stmt;
$this->next();
}
}
示例11: getReferers
/**
* Get list of referers ordered by it's count
*
* @param \Doctrine\DBAL\Query\QueryBuilder $query
* @param int $limit
* @param int $offset
*
* @return array
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getReferers($query, $limit = 10, $offset = 0)
{
$query->select('h.referer, count(h.referer) as sessions')->groupBy('h.referer')->orderBy('sessions', 'DESC')->setMaxResults($limit)->setFirstResult($offset);
return $query->execute()->fetchAll();
}
示例12: getMostVisited
/**
* Get list of referers ordered by it's count
*
* @param \Doctrine\DBAL\Query\QueryBuilder $query
* @param int $limit
* @param int $offset
* @param string $column
* @param string $as
*
* @return array
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getMostVisited($query, $limit = 10, $offset = 0, $column = 'p.hits', $as = '')
{
if ($as) {
$as = ' as "' . $as . '"';
}
$query->select('p.title, p.id, ' . $column . $as)->groupBy('p.id, p.title, ' . $column)->orderBy($column, 'DESC')->setMaxResults($limit)->setFirstResult($offset);
return $query->execute()->fetchAll();
}
示例13: make
/**
* @param array $request
* @return array
*/
public function make(array $request)
{
$output = ['data' => [], 'draw' => $request['draw'], 'recordsFiltered' => 0, 'recordsTotal' => 0];
/**
* Order By
*/
if (isset($request['order'])) {
for ($i = 0; $i < count($request['order']); ++$i) {
$j = intval($request['order'][$i]['column']);
if ($request['columns'][$j]['orderable'] != 'true') {
continue;
}
$column = $request['columns'][$j]['data'];
$sort = $request['order'][$i]['dir'];
$this->query->addOrderBy($column, $sort);
}
}
/**
* Count All
*/
$temp = clone $this->query;
$temp->resetQueryPart('select');
$temp->resetQueryPart('orderBy');
$temp->select("COUNT(*)");
$output['recordsTotal'] = $temp->execute()->fetchColumn(0);
/**
* Filter
*/
for ($i = 0; $i < count($request['columns']); ++$i) {
if ($request['columns'][$i]['searchable'] != 'true') {
continue;
}
$value = $request['columns'][$i]['search']['value'];
if (strlen($value) > 0) {
$column = $request['columns'][$i]['data'];
$value = $this->query->getConnection()->quote("{$value}%");
$this->query->andHaving($this->query->expr()->like($column, $value));
}
}
/**
* Search
*/
if (isset($request['search'])) {
$value = $request['search']['value'];
if (strlen($value) > 0) {
for ($i = 0; $i < count($request['columns']); ++$i) {
if ($request['columns'][$i]['searchable'] != 'true') {
continue;
}
$column = $request['columns'][$i]['data'];
$this->query->orHaving($this->query->expr()->like($column, ':search'));
}
$this->query->setParameter('search', "%{$value}%");
}
}
/**
* Count Filtered
*/
$temp = clone $this->query;
$temp->resetQueryPart('orderBy');
$output['recordsFiltered'] = $temp->execute()->rowCount();
/**
* Limit
*/
if (isset($request['start'])) {
$this->query->setFirstResult($request['start']);
}
if (isset($request['length'])) {
$this->query->setMaxResults($request['length']);
}
/**
* Fetch Results
*/
$output['data'] = $this->query->execute()->fetchAll(\PDO::FETCH_ASSOC);
/**
* Add Filter
*/
return $output;
}
示例14: findOneWith
/**
* Internal method to hydrate and return a single QueryBuilder result
*
* @return Entity | false
**/
protected function findOneWith(QueryBuilder $query)
{
$result = $query->execute()->fetch();
if ($result) {
return $this->hydrate($result, $query);
} else {
return false;
}
}
示例15: afterOperations
/**
* @param QueryBuilder $data
* @return Traversable
*/
protected function afterOperations($data)
{
return new ArrayIterator($data->execute()->fetchAll(PDO::FETCH_OBJ));
}