Zend 查询在成功添加行时也不返回任何内容
我的 zend 查询有问题吗?这些查询扩展了 Zend_Db_Table_Abstract
类?
成功更新后更新将返回零 (0),它也应该是 1。添加新用户在成功插入时不会返回任何内容。
请帮我。
/*
* Adding new user into database
* @params unknown_type $title, $firstName, $lastName
* @return boolean $sql
*/
public function addNewUser( $title, $firstName, $lastName ) {
$data = array (
'user_id' => '',
'title' => $title,
'first_name' => $firstName,
'last_name' => $lastName,
);
$result = $this->insert($data);
return $result;
}
/*
* updating user details using given user id
* @params unknown_type values $userId, $title, $firstName, $lastName
* @return nuumber of rows update, hopefully 1
*/
public function updateUserDetails( $userId, $title, $firstName, $lastName )
{ //echo $userId;
$data = array ( 'first_name' => $firstName, 'last_name' => $lastName );
$where = $this ->getAdapter()
->quoteInto('user_id = ?', $userId);
$result = $this ->update($data, $where );
return $result;
}
Is something wrong with my zend queries these are extending Zend_Db_Table_Abstract
class?
Update is returning zero (0) on successful update also it should be one. Adding new user is return nothing on successful insert.
Please help me.
/*
* Adding new user into database
* @params unknown_type $title, $firstName, $lastName
* @return boolean $sql
*/
public function addNewUser( $title, $firstName, $lastName ) {
$data = array (
'user_id' => '',
'title' => $title,
'first_name' => $firstName,
'last_name' => $lastName,
);
$result = $this->insert($data);
return $result;
}
/*
* updating user details using given user id
* @params unknown_type values $userId, $title, $firstName, $lastName
* @return nuumber of rows update, hopefully 1
*/
public function updateUserDetails( $userId, $title, $firstName, $lastName )
{ //echo $userId;
$data = array ( 'first_name' => $firstName, 'last_name' => $lastName );
$where = $this ->getAdapter()
->quoteInto('user_id = ?', $userId);
$result = $this ->update($data, $where );
return $result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要插入用户 ID。它可能是一个自动增量整数主键(如果不是,它应该是)。返回的值正是新插入行的主键值。
除此之外,代码看起来还不错。
Do not insert the user ID. It's probably an auto increment integer primary key (if not, it should be). The returned value is precisely the newly inserted row's primary key value.
That apart, the code seems OK.
以下是我对如何改进这些方法的意见:
The following is my opinion on how to improve these methods a little bit:
如果您的 user_id 是自动递增的,则不要提供它。在 zend 上更新时,如果您的更新值与现有值相同,那么您将始终得到 0。只有当您真正更新数据库中的某些内容时,您才会在更新数据时得到 1。
If your user_id is auto increment then don't provide it. And while updating on zend if your updating value is same as the existing one then you will always get 0. You will get 1 while updating the data only when you are really updating something in your DB.