如何测试我的MySQL更新查询在CodeIgniter中是否成功? [英] How do I test if my MySQL update query was successful in CodeIgniter?
本文介绍了如何测试我的MySQL更新查询在CodeIgniter中是否成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型函数,可以在我的CodeIgniter应用程序中更新用户:
I have a model function that updates a user in my CodeIgniter application:
// updates first of a user, return true if successful, false if not.
public function updateFirstName($userId, $newFirstName) {
$this->db->query("UPDATE users SET firstName='$newFirstName' WHERE id=$userId");
return // whether request was successful?
}
如何返回一个布尔值,以确保ID为$userId
的用户已更新?例如,如果未找到ID为$userId
的用户,则应返回false.
How do I return a boolean value that ensures the user of ID $userId
has been updated? For instance, it should return false if no user was found with ID $userId
.
推荐答案
That will tell you how many rows were updated.
这篇关于如何测试我的MySQL更新查询在CodeIgniter中是否成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文