本文整理汇总了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");
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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];
}
示例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();
}
}
示例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);
}
示例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;
}
示例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");
}