• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Query\QueryBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder类的具体用法?PHP QueryBuilder怎么用?PHP QueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了QueryBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * @param QueryBuilder $queryBuilder
  * @param $callback
  * @param int|null $limit
  * @param int $maxAttempts
  * @throws DBALWalkerException
  * @throws DBALException
  */
 public function run(QueryBuilder $queryBuilder, $callback, $limit = null, $maxAttempts = 10)
 {
     if (!is_callable($callback)) {
         throw new DBALWalkerException('$callback is not callable');
     }
     if (!is_null($limit)) {
         $queryBuilder->setMaxResults($limit);
     } else {
         $limit = $queryBuilder->getMaxResults();
     }
     if (is_null($limit)) {
         $limit = PHP_INT_MAX;
     }
     $offset = 0;
     do {
         $rows = [];
         $errors = $maxAttempts;
         while (true) {
             try {
                 $rows = $queryBuilder->setFirstResult($offset)->execute()->fetchAll();
                 break;
             } catch (DBALException $e) {
                 if ($errors-- == 0) {
                     throw $e;
                 }
                 $queryBuilder->getConnection()->connect();
             }
         }
         call_user_func($callback, $rows, $offset, $limit);
         $offset += $limit;
     } while (count($rows) >= $limit);
 }
开发者ID:octava,项目名称:replication,代码行数:40,代码来源:Walker.php


示例2: buildQuery

 /**
  * {@inheritdoc}
  */
 public function buildQuery(QueryBuilder $queryBuilder, array $values = array())
 {
     if (!array_key_exists($this->getName(), $values) || 0 === count($values[$this->getName()])) {
         return;
     }
     $queryBuilder->andWhere($queryBuilder->expr()->in('response.companyType', $values[$this->getName()]));
 }
开发者ID:Volyz,项目名称:barometre,代码行数:10,代码来源:CompanyTypeFilter.php


示例3: __construct

 /**
  * @param QueryBuilder  $qb
  * @param callable|null $countQueryBuilderModifier
  */
 public function __construct(QueryBuilder $qb, callable $countQueryBuilderModifier = null)
 {
     $this->qb = $qb;
     $this->countQueryBuilderModifier = $countQueryBuilderModifier ?: function (QueryBuilder $qb) {
         return $qb->select('COUNT(*)');
     };
 }
开发者ID:kbond,项目名称:porpaginas,代码行数:11,代码来源:DBALQueryBuilderResult.php


示例4: filters

 /**
  * @param $tableName
  * @param $conditions
  *
  * @return array
  *
  * @throws LookupError
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <[email protected]>
  */
 public static function filters(QueryBuilder $queryBuilder, $conditions)
 {
     // default lookup is equal
     $lookup = 'eq';
     // we add the or conditions afterwards to avoid them being mistaken for "and" conditions when they come first
     $or_combine = [];
     $and_combine = [];
     // create where clause from the conditions given
     foreach ($conditions as $condition) {
         foreach ($condition as $key => $value) {
             $column = self::getLookupColumn($key);
             $lookup = self::getLookUP($key);
             $value = self::prepareValue($value, $lookup);
             echo self::$lookuOptions[$lookup] . '<br>';
             echo $queryBuilder->createNamedParameter($value) . '<br>';
             echo $value . '<br>';
             $lookupCondition = sprintf(self::$lookuOptions[$lookup], $queryBuilder->createNamedParameter($value));
             $queryString = sprintf('%s %s', $column, $lookupCondition);
             if (self::combine($key) === self::$or) {
                 $queryBuilder->orWhere($queryString);
             } else {
                 $queryBuilder->andWhere($queryString);
             }
         }
     }
 }
开发者ID:eddmash,项目名称:powerorm,代码行数:38,代码来源:Lookup.php


示例5: logBuilder

 /**
  * @param QueryBuilder $builder
  */
 public static function logBuilder($builder)
 {
     $sql = $builder->getSQL();
     $params = $builder->getParameters();
     self::log("Running Query: " . $sql . " with params:");
     self::logObject($params);
 }
开发者ID:matheusviegas,项目名称:crudkit,代码行数:10,代码来源:LoggingHelper.php


示例6: process

 /**
  * Applies operation to data source and returns modified data source.
  *
  * @param QueryBuilder $src
  * @param OperationInterface|SortOperation $operation
  * @return QueryBuilder
  */
 public function process($src, OperationInterface $operation)
 {
     $field = $operation->getField();
     $order = $operation->getOrder();
     $src->orderBy($field, $order);
     return $src;
 }
开发者ID:view-components,项目名称:doctrine-data-processing,代码行数:14,代码来源:SortProcessor.php


示例7: __invoke

 /**
  * @param QueryBuilder $builder
  * @param $column
  * @param $value
  * @throws Exception
  * @return string
  */
 public function __invoke(QueryBuilder $builder, $column, $value)
 {
     if (!is_array($value)) {
         throw new Exception("Use of IN operator expects value to be array. Got " . gettype($value) . ".");
     }
     return $column . ' IN (' . $builder->createPositionalParameter($value, Connection::PARAM_STR_ARRAY) . ')';
 }
开发者ID:vlucas,项目名称:spot2,代码行数:14,代码来源:In.php


示例8: match

 public function match(QueryBuilder $qb)
 {
     if ($this->has('username')) {
         $qb->andWhere('u.username = :username');
         $qb->setParameter('username', $this->get('username'));
     }
 }
开发者ID:comphppuebla,项目名称:restful-extensions,代码行数:7,代码来源:FilterByUsernameSpecification.php


示例9: finalizeQuery

 public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
 {
     $paramcount = 0;
     if (!empty($this->gIDs)) {
         $validgids = array();
         foreach ($this->gIDs as $gID) {
             if ($gID > 0) {
                 $validgids[] = $gID;
             }
         }
         if (!empty($validgids)) {
             $query->innerJoin('p', 'VividStoreProductGroups', 'g', 'p.pID = g.pID and g.gID in (' . implode(',', $validgids) . ')');
             if (!$this->groupMatchAny) {
                 $query->having('count(g.gID) = ' . count($validgids));
             }
         }
     }
     switch ($this->sortBy) {
         case "alpha":
             $query->orderBy('pName', 'ASC');
             break;
         case "date":
             $query->orderBy('pDateAdded', 'DESC');
             break;
         case "popular":
             $pr = new StoreProductReport();
             $pr->sortByPopularity();
             $products = $pr->getProducts();
             $pIDs = array();
             foreach ($products as $product) {
                 $pIDs[] = $product['pID'];
             }
             foreach ($pIDs as $pID) {
                 $query->addOrderBy("pID = ?", 'DESC')->setParameter($paramcount++, $pID);
             }
             break;
     }
     switch ($this->featured) {
         case "featured":
             $query->andWhere("pFeatured = 1");
             break;
         case "nonfeatured":
             $query->andWhere("pFeatured = 0");
             break;
     }
     if (!$this->showOutOfStock) {
         $query->andWhere("pQty > 0 OR pQtyUnlim = 1");
     }
     if ($this->activeOnly) {
         $query->andWhere("pActive = 1");
     }
     if (is_array($this->cIDs) && !empty($this->cIDs)) {
         $query->innerJoin('p', 'VividStoreProductLocations', 'l', 'p.pID = l.pID and l.cID in (' . implode(',', $this->cIDs) . ')');
     }
     $query->groupBy('p.pID');
     if ($this->search) {
         $query->andWhere('pName like ?')->setParameter($paramcount++, '%' . $this->search . '%');
     }
     return $query;
 }
开发者ID:pvernaglia,项目名称:vivid_store,代码行数:60,代码来源:ProductList.php


示例10: finalizeQuery

 public function finalizeQuery(\Doctrine\DBAL\Query\QueryBuilder $query)
 {
     if (!$this->includeAllGroups) {
         $query->andWhere('g.gID > :minGroupID');
         $query->setParameter('minGroupID', REGISTERED_GROUP_ID);
     }
     return $query;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:8,代码来源:GroupList.php


示例11: testSetQueryBuilder02

 public function testSetQueryBuilder02()
 {
     $contain = $this->testConstruct02();
     $queryBuilder = new QueryBuilder($this->getConnection());
     $queryBuilder->select('*')->from('table', 't');
     $contain->setQueryBuilder($queryBuilder);
     return $contain;
 }
开发者ID:solire,项目名称:trieur,代码行数:8,代码来源:Contain.php


示例12: sort

 /**
  * @param QueryBuilder  $queryBuilder
  * @param SortInterface $sort
  * @param Mapping       $mapping
  */
 public static function sort(QueryBuilder $queryBuilder, SortInterface $sort, Mapping $mapping)
 {
     $columns = $mapping->map();
     foreach ($sort->orders() as $propertyName => $order) {
         self::guardColumnExists($columns, $propertyName);
         $queryBuilder->orderBy($columns[$propertyName], $order->isAscending() ? Order::ASCENDING : Order::DESCENDING);
     }
 }
开发者ID:PHPRepository,项目名称:sql-repository,代码行数:13,代码来源:SqlSorter.php


示例13: addQueryFromBuilder

 /**
  * Add a query from a query builder
  *
  * @param QueryBuilder $qb
  * @return $this
  */
 public function addQueryFromBuilder(QueryBuilder $qb)
 {
     /**
      * @TODO : How to manage query params ?
      */
     $this->queries[] = new Query($qb->getSQL());
     return $this;
 }
开发者ID:itkg,项目名称:core,代码行数:14,代码来源:Loader.php


示例14: match

 /**
  * @see \ComPHPPuebla\Doctrine\Query\Specification::match()
  */
 public function match(QueryBuilder $qb)
 {
     if ($this->has('page')) {
         $this->page = $this->get('page');
         $this->initPageSize();
         $qb->setFirstResult($this->calculateOffset())->setMaxResults($this->pageSize);
     }
 }
开发者ID:comphppuebla,项目名称:restful-extensions,代码行数:11,代码来源:PaginationSpecification.php


示例15: testItShouldWorksWithParametersInTheOrX

 public function testItShouldWorksWithParametersInTheOrX()
 {
     $qb = new QueryBuilder($this->connection);
     $qb->select('p.id')->from('posts', 'p')->setParameter('status', 'odd');
     $aclFilter = new DoctrineDbalAclFilter($qb);
     $aclFilter->setAclSchema($this->aclSchema);
     $aclFilter->apply('p', 'id', 'post-', ['user-1'], 1, ['status = :status']);
     $this->assertEquals(['status' => 'odd', 'acl_prefix' => 'post-', 'acl_identifiers' => ['user-1'], 'acl_mask' => 1], $qb->getParameters());
 }
开发者ID:alexdpy,项目名称:acl,代码行数:9,代码来源:DoctrineDbalAclFilterTest.php


示例16: getDataProvider

 protected function getDataProvider()
 {
     if (!$this->provider) {
         $builder = new QueryBuilder(Connection::get());
         $builder->select('*')->from('test_users');
         $this->provider = new DoctrineDataProvider($builder);
     }
     return $this->provider;
 }
开发者ID:view-components,项目名称:doctrine-data-processing,代码行数:9,代码来源:DoctrineTestTrait.php


示例17: setAddValues

 private function setAddValues(array $serialized, QueryBuilder $qb)
 {
     $i = 0;
     foreach ($serialized as $column => $value) {
         $qb->setValue($column, '?');
         $qb->setParameter($i, $value);
         ++$i;
     }
 }
开发者ID:ThreeDotsLabs,项目名称:crm,代码行数:9,代码来源:DoctrineStorage.php


示例18: loadUserByUsername

 /**
  * Load user by username
  * 
  * @param string $username
  * @return User
  * @throws \Exception
  */
 public function loadUserByUsername($username)
 {
     $qb = new QueryBuilder($this->db);
     $stmt = $qb->select('username, password, roles')->from('users', 'u')->where('u.username = :username')->andWhere('u.active = 1')->setParameter('username', $username)->execute();
     if (!($user = $stmt->fetchObject())) {
         throw new \Exception(sprintf('User "%s" not found.', $username));
     }
     return new User($user->username, $user->password, explode(',', $user->roles), true, true, true, true);
 }
开发者ID:avlima,项目名称:silexmantic-skeleton,代码行数:16,代码来源:UserProvider.php


示例19: buildQuery

 /**
  * {@inheritdoc}
  */
 public function buildQuery(QueryBuilder $queryBuilder, array $values = [])
 {
     if (!array_key_exists($this->getName(), $values) || 0 === count($values[$this->getName()])) {
         return;
     }
     $campaigns = array_map(function (Campaign $item) {
         return $item->getId();
     }, $values[$this->getName()]->toArray());
     $queryBuilder->andWhere($queryBuilder->expr()->in('response.campaign_id', $campaigns));
 }
开发者ID:Volyz,项目名称:barometre,代码行数:13,代码来源:CampaignFilter.php


示例20: process

 /**
  * Applies operation to data source and returns modified data source.
  *
  * @param QueryBuilder $src
  * @param OperationInterface|FilterOperation $operation
  * @return QueryBuilder
  */
 public function process($src, OperationInterface $operation)
 {
     $value = $operation->getValue();
     $operator = $operation->getOperator();
     $fieldName = $operation->getField();
     $parameterName = 'p' . md5($fieldName . $operator);
     $src->andWhere("{$fieldName} {$operator} :{$parameterName}");
     $src->setParameter($parameterName, $value);
     return $src;
 }
开发者ID:view-components,项目名称:doctrine-data-processing,代码行数:17,代码来源:FilterProcessor.php



注:本文中的Doctrine\DBAL\Query\QueryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Schema\AbstractSchemaManager类代码示例发布时间:2022-05-23
下一篇:
PHP Platforms\AbstractPlatform类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap