Symfony中的自定义SQL查询无法正常工作

时间:2011-01-20 05:21:10

标签: sql mysql symfony1 doctrine

  

可能重复:
  Trouble creating MySQL query in Symfony containing JOIN and RAND()

SELECT s.content 
FROM table SdumpPost s
JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table) 
AS ss 
ON s.id >= ss.maxid 
LIMIT 1

输入:

$connection = Doctrine_Manager::connection();
$query = 'SELECT p.content FROM table Post p JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table) AS pp ON p.id >= pp.maxid LIMIT 1';
$statement = $connection->execute($query);

//retrieve random post
$result = $statement->fetch(PDO::FETCH_OBJ);

它不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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