开发者

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 ...'); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜