In Symfony, I personally use Doctrine_Query to question the database
$q = Doctrine_Query::create() ->from('User u') ->where('u.username = ?', $username) ->andWhere('u.password = ?', $password); $user = $q->fetchArray();
However , the outcomes are saved in a wide array. Can there be in whatever way will be able to allow it to be fetch an item rather than an assortment?
Also, are there more ways will be able to query the database in Symfony or must i use Doctrine's functions?
You should use
to fetch one record (object) or
to fetch several objects.
I take advantage of these almost each time after i use symfony. sometimes you have to fetch arrays for the reason that situation you should use data hydration like HYDRATE_ARRAY or HYDRATE_ARRAY_HIERARCHY for those who have a nested set.
For raw queries read this: raw sql in doctrine
I simply needed to use raw queries myself which is how it operates in symfony:
$pdo = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh(); $query = "SELECT name, slug, ( 3959 * acos( cos( radians(:lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( lat ) ) ) ) AS distance FROM rss_city WHERE (lat <> :lat and lng <> :lng)HAVING distance IS NOT NULL ORDER BY distance LIMIT 5"; $stmt = $pdo->prepare($query); $params = array( "lat" => $lat, "lng" => $lng ); $stmt->execute($params); $results = $stmt->fetchAll();
This question returns a range of the five nearest metropolitan areas to the lat / lng coordinates. I believe it's self-explanatory.