我是 PHP CodIgniter 的新手,MySql "Delete Join" 有一些错误的语法错误
I'm new in PHP CodIgniter, I have some wrong syntax error with MySql "Delete Join"
public function delete($group_id)
{
$this->db->where('t1.*, t2.*, t3.*, t4.*, t6.*, COUNT(t5.id) AS total_students')
->join('groups_days AS t6', 't1.group_id = t6.group_id')
->join('groups_members AS t5', 't1.group_id = t5.group_id')
->group_by('t1.group_id')
->delete("groups AS t1")
->result();
}
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students' at line 1
DELETE FROM `groups` AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students
Filename: D:/www/domains/uzdev/taraqqiyot/application/models/Group_model.php
我的删除不起作用并显示上述错误。这里有什么问题
根据这个 link 你不能用 CodeIgniter Active Records 做 delete 和 join:
link
另一种选择是使用与表数一样多的查询:
$this->db->delete('groups', array('group_id'=>$group_id));
$this->db->delete('groups_days', array('group_id'=>$group_id));
$this->db->delete('groups_members', array('group_id'=>$group_id));
public function delete($group_id)
{
$this->db->where('t1.*, t2.*, t3.*, t4.*, t6.*, COUNT(t5.id) AS total_students')
->join('groups_days AS t6', 't1.group_id = t6.group_id')
->join('groups_members AS t5', 't1.group_id = t5.group_id')
->group_by('t1.group_id')
->delete("groups AS t1")
->result();
}
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students' at line 1
DELETE FROM `groups` AS `t1` WHERE t1., t2., t3., t4., t6.*, COUNT(t5.id) AS total_students
Filename: D:/www/domains/uzdev/taraqqiyot/application/models/Group_model.php
我的删除不起作用并显示上述错误。这里有什么问题
根据这个 link 你不能用 CodeIgniter Active Records 做 delete 和 join: link
另一种选择是使用与表数一样多的查询:
$this->db->delete('groups', array('group_id'=>$group_id));
$this->db->delete('groups_days', array('group_id'=>$group_id));
$this->db->delete('groups_members', array('group_id'=>$group_id));