当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::connection方法代码示例

本文整理汇总了PHP中Cake\ORM\Query::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::connection方法的具体用法?PHP Query::connection怎么用?PHP Query::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Query的用法示例。


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

示例1: findByDistance

 /**
  * Find By Distance using spherical cosine law
  *
  * @param \Cake\ORM\Query $query Query to modify
  * @param array $options Options for the query
  * @throws GeoDistanceInvalidArgumentException If parameters are missing or invalid
  * @return \Cake\ORM\Query
  */
 public function findByDistance(Query $query, array $options)
 {
     // set up parameters
     $this->_validateOptions($options);
     $latitude = $options['latitude'];
     $longitude = $options['longitude'];
     $radius = $options['radius'];
     if (isset($options['units']) && !empty($options['units'])) {
         $units = $options['units'];
     } else {
         $units = $this->_config['units'];
     }
     $earthRadius = $this->_getEarthRadius($units);
     // construct query
     $sphericalCosineSql = "(:earth_radius * ACOS(\n            COS(RADIANS(:latitude)) *\n            COS(RADIANS({$this->_config['latitudeColumn']})) *\n            COS( RADIANS({$this->_config['longitudeColumn']}) - RADIANS(:longitude) ) +\n            SIN(RADIANS(:latitude)) *\n            SIN(RADIANS({$this->_config['latitudeColumn']}))\n        ) )";
     $connection = $query->connection();
     if ($connection->driver() instanceof Mysql) {
         $distance = "ROUND({$sphericalCosineSql}, 3)";
     } elseif ($connection->driver() instanceof Postgres) {
         $distance = "ROUND( CAST({$sphericalCosineSql} AS numeric), 3)";
     }
     $queryOptions = ['fields' => ['distance' => $distance], 'order' => ['distance ASC'], 'conditions' => ["{$distance} <= :radius"]];
     $query->find('all', $queryOptions)->autoFields(true)->bind(':earth_radius', $earthRadius, 'integer')->bind(':latitude', $latitude, 'float')->bind(':longitude', $longitude, 'float')->bind(':radius', $radius, 'float');
     return $query;
 }
开发者ID:chris48s,项目名称:cakephp-geodistance,代码行数:33,代码来源:GeoDistanceBehavior.php

示例2: _castValues

 /**
  * Casts all values from a row brought from a table to the correct
  * PHP type.
  *
  * @param Table $table The table object
  * @param array $values The values to cast
  * @return array
  */
 protected function _castValues($table, $values)
 {
     $alias = $table->alias();
     $driver = $this->_query->connection()->driver();
     if (empty($this->types[$alias])) {
         $schema = $table->schema();
         foreach ($schema->columns() as $col) {
             $this->types[$alias][$col] = Type::build($schema->columnType($col));
         }
     }
     foreach ($values as $field => $value) {
         if (!isset($this->types[$alias][$field])) {
             continue;
         }
         $values[$field] = $this->types[$alias][$field]->toPHP($value, $driver);
     }
     return $values;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:26,代码来源:ResultSet.php

示例3: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Query $query Query from where results come
  * @param \Cake\Database\StatementInterface $statement The statement to fetch from
  */
 public function __construct($query, $statement)
 {
     $repository = $query->repository();
     $this->_query = $query;
     $this->_statement = $statement;
     $this->_driver = $driver = $this->_query->connection()->driver();
     $this->_defaultTable = $this->_query->repository();
     $this->_calculateAssociationMap();
     $this->_hydrate = $this->_query->hydrate();
     $this->_entityClass = $repository->entityClass();
     $this->_useBuffering = $query->bufferResults();
     $this->_defaultAlias = $this->_defaultTable->alias();
     $this->_calculateColumnMap();
     $this->_calculateTypeMap();
     if ($this->_useBuffering) {
         $count = $this->count();
         $this->_results = new SplFixedArray($count);
     }
 }
开发者ID:QueenCityCodeFactory,项目名称:cakephp,代码行数:25,代码来源:ResultSet.php

示例4: _collectKeys

 /**
  * Helper function used to return the keys from the query records that will be used
  * to eagerly load associations.
  *
  * @param array $external the list of external associations to be loaded
  * @param \Cake\ORM\Query $query The query from which the results where generated
  * @param BufferedStatement $statement The statement to work on
  * @return array
  */
 protected function _collectKeys($external, $query, $statement)
 {
     $collectKeys = [];
     foreach ($external as $meta) {
         $instance = $meta->instance();
         if (!$instance->requiresKeys($meta->config())) {
             continue;
         }
         $source = $instance->source();
         $keys = $instance->type() === Association::MANY_TO_ONE ? (array) $instance->foreignKey() : (array) $instance->bindingKey();
         $alias = $source->alias();
         $pkFields = [];
         foreach ($keys as $key) {
             $pkFields[] = key($query->aliasField($key, $alias));
         }
         $collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
     }
     if (empty($collectKeys)) {
         return [[], $statement];
     }
     if (!$statement instanceof BufferedStatement) {
         $statement = new BufferedStatement($statement, $query->connection()->driver());
     }
     return [$this->_groupKeys($statement, $collectKeys), $statement];
 }
开发者ID:sergiochollet,项目名称:kiwi-cake,代码行数:34,代码来源:EagerLoader.php

示例5: assertSelectClause

 /**
  * Assertion method for select clause contents.
  *
  * @param array $expected Array of expected fields.
  * @param \Cake\ORM\Query $query The query to check.
  * @return void
  */
 protected function assertSelectClause($expected, $query)
 {
     if ($this->autoQuote) {
         $connection = $query->connection();
         foreach ($expected as $key => $value) {
             $expected[$connection->quoteIdentifier($key)] = $connection->quoteIdentifier($value);
             unset($expected[$key]);
         }
     }
     $this->assertEquals($expected, $query->clause('select'));
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:18,代码来源:HasManyTest.php

示例6: _driverClass

 /**
  * Gets the name of the class driver used by the given $query to access the DB.
  *
  * @param \Cake\ORM\Query $query The query to inspect
  * @return string Lowercased drive name. e.g. `mysql`
  */
 protected function _driverClass(Query $query)
 {
     $conn = $query->connection(null);
     list(, $driverClass) = namespaceSplit(strtolower(get_class($conn->driver())));
     return $driverClass;
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:12,代码来源:WhereScope.php

示例7: _assertFieldsPresent

 /**
  * Checks that the fetching query either has auto fields on or
  * has the foreignKey fields selected.
  * If the required fields are missing, throws an exception.
  *
  * @param \Cake\ORM\Query $fetchQuery The association fetching query
  * @param array $key The foreign key fields to check
  * @return void
  * @throws InvalidArgumentException
  */
 protected function _assertFieldsPresent($fetchQuery, $key)
 {
     $select = $fetchQuery->aliasFields($fetchQuery->clause('select'));
     if (empty($select)) {
         return;
     }
     $missingKey = function ($fieldList, $key) {
         foreach ($key as $keyField) {
             if (!in_array($keyField, $fieldList, true)) {
                 return true;
             }
         }
         return false;
     };
     $missingFields = $missingKey($select, $key);
     if ($missingFields) {
         $driver = $fetchQuery->connection()->driver();
         $quoted = array_map([$driver, 'quoteIdentifier'], $key);
         $missingFields = $missingKey($select, $quoted);
     }
     if ($missingFields) {
         throw new InvalidArgumentException(sprintf('You are required to select the "%s" field(s)', implode(', ', (array) $key)));
     }
 }
开发者ID:nrother,项目名称:cakephp,代码行数:34,代码来源:SelectableAssociationTrait.php


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