Added Doctrine_Connection::queryOne()
This commit is contained in:
parent
ad595dd839
commit
6b4e032857
@ -150,6 +150,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
*/
|
*/
|
||||||
public function driverName($name) {
|
public function driverName($name) {
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* supports
|
||||||
|
*
|
||||||
|
* @param string $feature the name of the feature
|
||||||
|
* @return boolean whether or not this drivers supports given feature
|
||||||
|
*/
|
||||||
|
public function supports($feature) {
|
||||||
|
return (isset($this->supported[$feature]) &&
|
||||||
|
$this->supported[$feature] === 'emulated' ||
|
||||||
|
$this->supported[$feature]);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* returns a datadict object
|
* returns a datadict object
|
||||||
*
|
*
|
||||||
@ -316,6 +327,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
/**
|
/**
|
||||||
* query
|
* query
|
||||||
* queries the database using Doctrine Query Language
|
* queries the database using Doctrine Query Language
|
||||||
|
* returns a collection of Doctrine_Record objects
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* $users = $conn->query('SELECT u.* FROM User u');
|
* $users = $conn->query('SELECT u.* FROM User u');
|
||||||
@ -333,6 +345,34 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
|
|
||||||
return $parser->query($query, $params);
|
return $parser->query($query, $params);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* queries the database with limit and offset
|
* queries the database with limit and offset
|
||||||
* added to the query and returns a PDOStatement object
|
* added to the query and returns a PDOStatement object
|
||||||
@ -583,7 +623,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
$record->getTable()->getListener()->onDelete($record);
|
$record->getTable()->getListener()->onDelete($record);
|
||||||
|
|
||||||
$this->commit();
|
$this->commit();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user