0

这是我在 phpmyadmin 中制定的一个更大查询的子集,但我对让它在我在 Joomla 中构建的组件中工作的语法有点迷茫和困惑。

在 phpmyadmin 中工作的代码:

drop table if exists tests_mod_ques;
create table tests_mod_ques as
select p.student_userid, q.question_mod, q.question_id, p.student_passedchk

from `tests_students` p 
inner join `tests_questions` q on p.question_id = q.question_id
group by  p.student_userid, q.question_mod, q.question_id, p.student_passedchk
;

引发 1064 语法错误的代码:

$query = parent::getListQuery(); 

$query->dropTable('#__tests_mod_ques', 'true');
$query->createTable('#__tests_mod_ques AS 
    select (p.student_userid
    , q.question_mod
    , q.question_id
    , p.student_passedchk)
    ');
$query->from('#__tests_students AS p');
$query->join('#__tests_questions AS q ON p.question_id = q.question_id');
$query->group('p.student_userid
    , q.question_mod
    , q.question_id
    , p.student_passedchk
    '); 

  ....  
    $db = $this->getDbo();
    return $query;  

我只测试了 dropTable 语句,即使它没有抛出错误,它也没有删除表,也没有显示在调试器中,所以我可能没有使用该权利: http://api.joomla.org/Joomla-Platform/Database/JDatabase.html#dropTable

除了这个之外,似乎找不到任何参考来创建: http://api.joomla.org/Joomla-Platform/Database/JDatabase.html#getTableCreate

我也有一个INSERT…ON DUPLICATE KEY UPDATE查询,我不知道如何处理。

谢谢!

编辑

我试过删除行作为一种解决方法,也没有注册。再次检查调试器,删除查询没有出现。

$query->delete('#__tests_mod_ques');

这应该根据http://api.joomla.org/Joomla-Platform/Database/JDatabaseQuery.html#$delete和工作http://docs.joomla.org/JDatabaseQuery::delete/1.6

令人沮丧!有人知道吗?

谢谢!

4

2 回答 2

0

问题应该是因为 $query 属于 JDatabaseQuery 类,因为你初始化它的方式,所以它只有这里列出的方法:http: //docs.joomla.org/JDatabaseQuery/1.6

您尝试调用的方法实际上是 JDatabase 的方法,您在最后创建了一个实例。因此,您应该能够执行 $db->createTable(... etc 并且它会实际运行。

于 2012-06-08T08:26:19.940 回答
0

您可以尝试以下方法 -

$query->createTable('#__tests_mod_ques AS 
select (p.student_userid
, q.question_mod
, q.question_id
, p.student_passedchk)
from #__tests_students AS p
inner join #__tests_questions AS q ON p.question_id = q.question_id
group by p.student_userid
, q.question_mod
, q.question_id
, p.student_passedchk');
于 2012-05-11T12:20:37.623 回答