How do I do this:
SELECT t.id 
FROM table t 
JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table) 
AS tt 
ON t.id >= tt.maxid 
LIMIT 1
in Symfony? (I know how to do basic stuff, but this is too much.
$connection = Doctrine_Manager::getConnection()->getDbh(); 
won't work... Try this:
$connection = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
Then:
$stmt = $connection->query('SELECT * FROM some_table');
$stmt->execute();
$result = $stmt->fetchAll();
    $connection = Doctrine_Manager::getConnection()->getDbh(); 
$result = $connection->query('SELECT ...'); 
    来源:https://stackoverflow.com/questions/4734841/trouble-creating-mysql-query-in-symfony-containing-join-and-rand