php - 获取真/假codeigniter插入功能
问题描述
每次我在模型中使用插入函数时,返回总是正确的,这是我的代码
public function insert_text($data)
{
return $this->db->table($this->table)->insert($data);
}
呼叫代码
if ($this->text->insert_text($data)) {
echo "success";
} else {
echo "failed";
}
即使执行失败(由于相同的主键已经存在),代码总是返回“成功”,如何解决?
谢谢
解决方案
检查是否插入成功
if ($this->db->insert_id()) {
echo "success";
} else {
echo "failed";
}
推荐阅读
- ios - 我正在寻找按离我当前位置最近的点进行排序 - Swift 中的 CLLocationCoordinate2D 数组
- php - 使用原始名称 File 的 save()
- subset - 在合金中获取签名子集
- c# - .NET Standard 中 JsonSerializer.SerializeToUtf8Bytes 的替代方案
- microsoft-graph-api - 为机器人重用 App Id 是好主意还是坏主意?
- apache-camel - Camel 3 - deadLetterChannel 的动态 uri
- angular - 有没有办法在方法中转换主题订阅以返回值
- javascript - React 道具更新是否足够快速和一致,以保持稳定的节奏并在音乐应用中触发音符?
- sql-server - 有没有办法在不使用 SQL 探查器的情况下查看 SQL 调用的来源?
- javascript - 在按钮单击中调用另一个函数只是返回空