Php 不允许Codeigniter删除,除非它们包含一个;其中;或;例如;条款
我有下一个查询并返回这个Php 不允许Codeigniter删除,除非它们包含一个;其中;或;例如;条款,php,codeigniter,Php,Codeigniter,我有下一个查询并返回这个 function delete_dispatchByIdPlataforma($idPlataforma) { $this->db->delete("delete from dispatch where id_licencia in (select id_licencia from licencias where id_plataforma = $idPlataforma)"); } 所以我试了一下: $this-
function delete_dispatchByIdPlataforma($idPlataforma)
{
$this->db->delete("delete from dispatch where id_licencia in
(select id_licencia from licencias where id_plataforma = $idPlataforma)");
}
所以我试了一下:
$this->db->select('id_licencia');
$this->db->from('licencias');
$this->db->where('id_plataforma', $idPlataforma);
$where_clause = $this->db->get_compiled_select();
#Create main query
$this->db->where("`id_licencia` IN ($where_clause)", NULL, FALSE);
$this->db->delete('dispatch');
但现在不会返回任何内容,也不会执行查询。最后,我进行了一次select WIT JOIN操作,只获取数组中的id,然后使用此id数组对活动记录进行了删除,如下所示。单击绿色勾号,您可以接受自己的答案。
// First get the id to delete of my table
function getIdDispatchToDelete($idPlataforma)
{
$this->db->select('ID_dispatch');
$this->db->from('dispatch');
$this->db->join('licencias', 'licencias.id_licencia = dispatch.id_licencia');
$this->db->where('licencias.id_plataforma', $idPlataforma);
$query = $this->db->get();
//echo $this->db->last_query();die();
if($query){
if($query->num_rows>0){
foreach ($query->result() as $fila){
$data[] = $fila->ID_dispatch;
}
return $data;
}
}else
log_message('error', 'No se han encontrado Dispatch a borrar'.$this->db->_error_message().' - '.$this->db->last_query());
}
// Seccond i did the delete whit the id got it.
function delete_dispatchByIdPlataforma($idPlataforma)
{
$idDispatch = $this->getIdDispatchToDelete($idPlataforma);
$this->db->where_in('id_dispatch', $idDispatch);
$this->db->delete('dispatch');
}