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


PHP Doctrine_Query::query方法代码示例

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


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

示例1: testIterator

    public function testIterator() {
        $graph = new Doctrine_Query($this->connection);
        $entities = $graph->query("FROM Entity");
        $i = 0;
        foreach($entities as $entity) {
            $this->assertEqual(gettype($entity->name),"string");
            $i++;
        }
        $this->assertTrue($i == $entities->count());
        
        $user = $graph->query("FROM User");
        foreach($user[1]->Group as $group) {
            $this->assertTrue(is_string($group->name));
        }     
        
        $user = new User();
        $user->name = "tester";
        
        $user->Address[0]->address = "street 1";
        $user->Address[1]->address = "street 2";
        
        $this->assertEqual($user->name, "tester");
        $this->assertEqual($user->Address[0]->address, "street 1");
        $this->assertEqual($user->Address[1]->address, "street 2");

        foreach($user->Address as $address) {
            $a[] = $address->address;
        }
        $this->assertEqual($a, array("street 1", "street 2"));   

        $user->save();
        
        $user = $user->getTable()->find($user->id);
        $this->assertEqual($user->name, "tester");
        $this->assertEqual($user->Address[0]->address, "street 1");
        $this->assertEqual($user->Address[1]->address, "street 2");
        
        $user = $user->getTable()->find($user->id);
        $a = array();
        foreach($user->Address as $address) {
            $a[] = $address->address;
        }
        $this->assertEqual($a, array("street 1", "street 2"));                                    


        $user = $graph->query("FROM User");
    }
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:47,代码来源:BatchIteratorTestCase.php

示例2: execute

 public function execute()
 {
     Doctrine::loadModels($this->getArgument('models_path'));
     $dql = $this->getArgument('dql_query');
     $query = new Doctrine_Query();
     $this->notify('executing: "' . $dql . '"');
     $results = $query->query($dql);
     $this->printResults($results);
 }
开发者ID:kirvin,项目名称:the-nerdery,代码行数:9,代码来源:Dql.php

示例3: execute

 public function execute()
 {
     Doctrine::loadModels($this->getArgument('models_path'));
     $dql = $this->getArgument('dql_query');
     $query = new Doctrine_Query();
     $params = $this->getArgument('params');
     $params = $params ? explode(',', $params) : array();
     $this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')');
     $results = $query->query($dql, $params, Doctrine::HYDRATE_ARRAY);
     $this->_printResults($results);
 }
开发者ID:stelaireri,项目名称:Hive,代码行数:11,代码来源:Dql.php

示例4: findByDql

 /**
  * findByDql
  * finds records with given DQL where clause
  * returns a collection of records
  *
  * @param string $dql               DQL after WHERE clause
  * @param array $params             query parameters
  * @param int $hydrationMode        Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD
  * @return Doctrine_Collection
  */
 public function findByDql($dql, $params = array(), $hydrationMode = null)
 {
     $parser = new Doctrine_Query($this->_conn);
     $component = $this->getComponentName();
     $query = 'FROM ' . $component . ' dctrn_find WHERE ' . $dql;
     return $parser->query($query, $params, $hydrationMode);
 }
开发者ID:mediasadc,项目名称:alba,代码行数:17,代码来源:Table.php

示例5: loadRelated

 /**
  * Load all relationships or the named relationship passed
  *
  * @param mixed $name
  * @return boolean
  */
 public function loadRelated($name = null)
 {
     $list = array();
     $query = new Doctrine_Query($this->_table->getConnection());
     if (!isset($name)) {
         foreach ($this->data as $record) {
             $value = $record->getIncremented();
             if ($value !== null) {
                 $list[] = $value;
             }
         }
         $query->from($this->_table->getComponentName());
         $query->where($this->_table->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)), 0, -2) . ')');
         return $query;
     }
     $rel = $this->_table->getRelation($name);
     if ($rel instanceof Doctrine_Relation_LocalKey || $rel instanceof Doctrine_Relation_ForeignKey) {
         foreach ($this->data as $record) {
             $list[] = $record[$rel->getLocal()];
         }
     } else {
         foreach ($this->data as $record) {
             $value = $record->getIncremented();
             if ($value !== null) {
                 $list[] = $value;
             }
         }
     }
     $dql = $rel->getRelationDql(count($list), 'collection');
     $coll = $query->query($dql, $list);
     $this->populateRelated($name, $coll);
 }
开发者ID:stelaireri,项目名称:Hive,代码行数:38,代码来源:Collection.php

示例6: queryOne

 /**
  * query
  * queries the database using Doctrine Query Language and returns
  * the first record found
  *
  * <code>
  * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1));
  *
  * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?',
  *         array('someone', 'password')
  *         );
  * </code>
  *
  * @param string $query             DQL query
  * @param array $params             query parameters
  * @see Doctrine_Query
  * @return Doctrine_Record|false    Doctrine_Record object on success,
  *                                  boolean false on failure
  */
 public function queryOne($query, array $params = array())
 {
     $parser = new Doctrine_Query($this);
     $coll = $parser->query($query, $params);
     if (!$coll->contains(0)) {
         return false;
     }
     return $coll[0];
 }
开发者ID:adnanali,项目名称:munch,代码行数:28,代码来源:Connection.php

示例7: testNotEqual

 public function testNotEqual()
 {
     try {
         $query = new Doctrine_Query($this->connection);
         $ret = $query->query("FROM EnumTest WHERE EnumTest.status != 'closed'");
         $this->assertEqual(count($ret), 1);
     } catch (Exception $e) {
         $this->fail();
     }
 }
开发者ID:kaakshay,项目名称:audience-insight-repository,代码行数:10,代码来源:EnumTestCase.php

示例8: testFetchingWithSmartConversion

 public function testFetchingWithSmartConversion()
 {
     $query = new Doctrine_Query($this->connection);
     $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = false');
     $this->assertEqual(count($ret), 1);
     $query = new Doctrine_Query($this->connection);
     $ret = $query->query('FROM BooleanTest WHERE BooleanTest.is_working = true');
     $this->assertEqual(count($ret), 1);
 }
开发者ID:swk,项目名称:bluebox,代码行数:9,代码来源:BooleanTestCase.php

示例9: findBySql

 /**
  * findByDql
  * finds records with given DQL where clause
  * returns a collection of records
  *
  * @param string $dql               DQL after WHERE clause
  * @param array $params             query parameters
  * @return Doctrine_Collection
  */
 public function findBySql($dql, array $params = array())
 {
     $q = new Doctrine_Query($this->conn);
     $users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params);
     return $users;
 }
开发者ID:snouhaud,项目名称:camptocamp.org,代码行数:15,代码来源:Table.php

示例10: testMultipleOneToManyFetchingWithOrderBy

 public function testMultipleOneToManyFetchingWithOrderBy()
 {
     $query = new Doctrine_Query();
     $users = $query->query("FROM User.Album.Song WHERE User.id IN (4,5) ORDER BY User.Album.Song.title DESC");
 }
开发者ID:swk,项目名称:bluebox,代码行数:5,代码来源:MultiJoinTestCase.php


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