开发者

Custom SQL query in Symfony not working [duplicate]

开发者 https://www.devze.com 2023-02-05 21:45 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Trouble creating MySQL query in Symfony containing JOIN and RAND()
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

精彩评论

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

关注公众号