Trouble creating MySQL query in Symfony containing JOIN and RAND()
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 Symf开发者_开发问答ony? (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 ...');
精彩评论