Trouble creating MySQL query in Symfony containing JOIN and RAND()

拈花ヽ惹草 提交于 2019-12-01 13:10:20

问题


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.


回答1:


$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();



回答2:


$connection = Doctrine_Manager::getConnection()->getDbh(); 
$result = $connection->query('SELECT ...'); 


来源:https://stackoverflow.com/questions/4734841/trouble-creating-mysql-query-in-symfony-containing-join-and-rand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!