我正在使用codeigniter版本2.0.3.我正在尝试使用更新查询后获取受影响的行数
$this->db->affected_rows
Run Code Online (Sandbox Code Playgroud)
即使没有更新行,它也总是返回1.我试过了
mysql_affected_rows()
Run Code Online (Sandbox Code Playgroud)
如果查询失败,则返回-1;如果没有更新记录,则返回0.
编辑包括我的代码
我正在使用
$country_id = $this->input->post('country_id');
$time=$this->input->post('time');
$insert_array = array(
'country' => $this->input->post('name')
);
$this->db->update('country_master', $insert_array, array("country_id" => $country_id,"last_updated"=>$time));
$afftectedRows=$this->db->affected_rows();
Run Code Online (Sandbox Code Playgroud)
Nic*_*ick 20
其实我的代码是这样的
if (!$country_id) {
$this->db->insert('country_master', $insert_array);
$id = $this->db->insert_id();
} else {
$this->db->update('country_master', $insert_array, array("country_id" => $country_id, "last_updated" => $time));
}
$afftectedRows = $this->db->affected_rows();
Run Code Online (Sandbox Code Playgroud)
我修改了它
if (!$country_id) {
$this->db->insert('country_master', $insert_array);
$id = $this->db->insert_id();
} else {
$this->db->update('country_master', $insert_array, array("country_id" => $country_id, "last_updated" => $time));
$afftectedRows = $this->db->affected_rows();
}
Run Code Online (Sandbox Code Playgroud)
它的工作正常.
非常感谢你的回复..
| 归档时间: |
|
| 查看次数: |
66533 次 |
| 最近记录: |