开发者

Custom SQL query in Symfony not working [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

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

entered as:

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

It's not working. Any ideas?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜