如何进行批量删除呢????
function deleteseat($id){
if($id!=0)
{
$this->db->delete("city",array("id"=>$id));
return true;
}
else
{
$ValidDealers=$this->input->post('id');
print_r($ValidDealers);
$this->db->where_in('id',array(($ValidDealers)));
$this->db->delete('city');
return true;
}
}
我的 $ValidDealers获得了是数组Array ( => 1 => 2 => 3) 但是删不成功?这是为什么呢? Active Record 的 delete 不支持 where_in 那要怎么写sql语句呢? Active Record 的 delete 不支持 where_in
Hex 发表于 2009-12-28 15:10 http://codeigniter.org.cn/forums/images/common/back.gif
用原生的sql语句可以吧
$query_string = "delete from ...";
$this -> db -> query($query_string); 应该支持,我一直是这么用正常.
function delRecords($id)
{
$this->db->where_in('id',$id);
$this->db->delete('news');
}
$id为一维数组. 不清楚,支持 where_in不支持的我后来我改了sql与句就好了
function deletecity($id)
{
if($id!=0)
{
$this->db->delete("city",array("id"=>$id));
return true;
}
else
{
$arr=$this->input->post('id');
$sql="delete from `city` where id in (".join(',',$arr).")";
$query=$this->db->query($sql);
return true;
}
} 把它写成SQL就完成批量的,我这是一种方法 这个支持呀! where_in不支持的我后来我改了sql与句就好了
$arr=$this->input->post('id');
$sql="delete from `city` where id in (".join(',',$arr).")";
...
stutrip 发表于 2009-12-29 15:52 http://codeigniter.org.cn/forums/images/common/back.gif
input->post()只能过滤跨站脚本攻击(XSS),无法抵御SQL注入
红字部分没有安全检测,存在注入漏洞,建议用foreach检测每个id为数字类型if(is_int($val))
页:
[1]
2