【发布时间】:2012-04-01 19:34:58
【问题描述】:
这是我在 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 工作
令人沮丧!有人知道吗?
谢谢!
【问题讨论】:
-
能否打印查询,以便查看它是否被 DB 类正确解释?
-
如果我做得对(这可能是一个大问题!)然后 dropTable 不会出现。在那里扔了一个
print_r($query);,dropTable 没有出现,但查询的其余部分(正在工作的...部分)出现了。它也没有出现在调试器中,为什么我认为我没有正确使用它但找不到好的例子。
标签: php joomla joomla1.7 joomla1.6 joomla2.5