303076060 发表于 2013-12-30 14:07:06

关于判断更新数据库是否成功?

本帖最后由 303076060 于 2013-12-30 14:08 编辑

请问各位是怎样判断的?
直接 用
return $this->db->insert($_table,$_data);
这样可以吗?
还是用
return $this->db->insert_id();
?
还有更新数据库里用

$this->db->where('id', $id);
return $this->db->update($_table,$_data);

这样判断,还是用
$this->db->where('id', $id);
$this->db->update($_table,$_data);
return $this->db->affected_rows();

$this->db->affected_rows()

loadinger 发表于 2013-12-31 09:55:22

$this->db->affected_rows();如果数据没有改动,会返回0....这就是个悲剧。

303076060 发表于 2013-12-31 17:41:35

loadinger 发表于 2013-12-31 09:55 static/image/common/back.gif
$this->db->affected_rows();如果数据没有改动,会返回0....这就是个悲剧。

{:soso_e136:}请问用那一种判断??

zyu 发表于 2014-1-3 20:04:00

insert 用 $this->db->insert($_table,$_data);    如果成功,返回是新ID值,否则空0
update 用 $this->db->affected_rows(); 如果成功,返回成功条目数量,一般是1,失败就空0。

自己判断一下即可

303076060 发表于 2014-1-5 20:31:02

zyu 发表于 2014-1-3 20:04 static/image/common/back.gif
insert 用 $this->db->insert($_table,$_data);    如果成功,返回是新ID值,否则空0
update 用 $this->db- ...

感谢!
页: [1]
查看完整版本: 关于判断更新数据库是否成功?