这是我在 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
令人沮丧!有人知道吗?
谢谢!