Zend Framwork 2 - Tablegateway - Updating only one column of a row in DB

995 views Asked by At

I have a table called users. It has the following columns:

id

name

username

email

User can not edit any data from this table except the username column. The question is that when user wants to edit his username, what would the query be in ZF2 Tablegateway?

In my controller I have a function called getUserTable(), as created in ZF2 manual also. So I am doing something like:

$this->getUserTable()->updateUser($id, $name);

And in UserTable.php class that is in Model folder I have a function called updateUser($id, $name).

My function look like this at the moment:

public function updateUser($id, $name){

  $user_id = $id;

  $username = $name;

  $this->tableGateway->update($username, array('id' => $user_id));

}

So Basically all I want to implement is:

Update users set 'username' = $username where 'id' = $user_id

1

There are 1 answers

0
venca On BEST ANSWER

->update (array ('username' => $username), array ('id = ?' => $id));

Sorry for formatting, I am writing on phone.