Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在包含JOIN和RAND()的Symfony中创建MySQL查询时出现问题_Sql_Mysql_Symfony 1.4 - Fatal编程技术网

在包含JOIN和RAND()的Symfony中创建MySQL查询时出现问题

在包含JOIN和RAND()的Symfony中创建MySQL查询时出现问题,sql,mysql,symfony-1.4,Sql,Mysql,Symfony 1.4,我如何做到这一点: 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 在Symfony?(我知道如何做基本的事情,但这太过分了 $connection = Doctrine_Manager::getConnection()->getDbh(); $result = $connection

我如何做到这一点:

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
在Symfony?(我知道如何做基本的事情,但这太过分了

$connection = Doctrine_Manager::getConnection()->getDbh(); 
$result = $connection->query('SELECT ...'); 
不起作用…试试这个:

$connection = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
然后:


我是将其放在action还是model类中?我会将所有与数据库相关的内容放在模型中,而不是action中。我已经对此进行了一段时间的研究:它不断返回一个错误,表示connection not found..argh..我如何使用常规DQL(creatquery()->等)来实现这一点?
$connection = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$stmt = $connection->query('SELECT * FROM some_table');
$stmt->execute();
$result = $stmt->fetchAll();