<p>When you take a look at the <a href="https://www.yiiframework.com/doc/api/1.1/CDbCommand#update-detail" rel="nofollow noreferrer">documentation</a> the interface for the <code>update</code> function is the following.</p>

<pre class="lang-PHP prettyprint-override"><code>public integer update(string $table, array $columns, mixed $conditions='', array $params=array ())
</code></pre>

<p>Thus your code should look like:</p>

<pre class="lang-PHP prettyprint-override"><code>public function updateUserName($userId, $updateUser)
{
    $update = craft()-&gt;db-&gt;createCommand()-&gt;update(
        'contest_user', 
        array('name' =&gt; $updateUser), 
        'id=:id',
        array(':id', $userId)
    );

    return $update;
}
</code></pre>

<p>You can see a working example here:</p>

<pre class="lang-PHP prettyprint-override"><code>// build and execute the following SQL:
// UPDATE `tbl_user` SET `name`=:name WHERE id=:id
$command-&gt;update('tbl_user', array(
    'name'=&gt;'Tester',
), 'id=:id', array(':id'=&gt;1));
</code></pre>

CC BY-SA 4.0
2018-10-16T14:04:59.813Z
Thx. It works. It's so easy when you think about it. I'm just a beginner. So there is plenty of practise to do.
olifantT
CC BY-SA 4.0
2018-10-16T13:39:20.483Z
2018-11-06T11:46:04.497Z
2018-11-06T11:46:04.497Z
Robin Schambach
<p>My problem is that I can't update the specific <code>$userId</code>. have the values I've selected. I also get an error:</p>

<blockquote>
  <p>Call to a member function where() on integer </p>
</blockquote>

<p>I just started to learn Craft. It can be simple for you but not for me.</p>

<pre><code>public function updateUserName($userId, $updateUser)
{

    $update = craft()-&gt;db-&gt;createCommand()-&gt;update('contest_user', array(
        'name' =&gt; $updateUser))-&gt;where('id', $userId);

    return $update;
}
</code></pre>

<plugin-development><templating><query><craft2><yii>
where command sql query not working
# where command sql query not working

(Asked by: username_0 on 2018-10-16)

My problem is that I can't update the specific $userId. have the values I've selected. I also get an error:

Call to a member function where() on integer 

I just started to learn Craft. It can be simple for you but not for me.
public function updateUserName($userId, $updateUser)
{

    $update = craft()->db->createCommand()->update('contest_user', array(
        'name' => $updateUser))->where('id', $userId);

    return $update;
}

**Tags:** plugin-development, templating, query, craft2, yii

---

## 1 answers

### Answer by username_1 on 2018-10-16. Score: 1 | Accepted answer

When you take a look at the documentation the interface for the update function is the following.
public integer update(string $table, array $columns, mixed $conditions='', array $params=array ())

Thus your code should look like:
public function updateUserName($userId, $updateUser)
{
    $update = craft()->db->createCommand()->update(
        'contest_user', 
        array('name' => $updateUser), 
        'id=:id',
        array(':id', $userId)
    );

    return $update;
}

You can see a working example here:
// build and execute the following SQL:
// UPDATE `tbl_user` SET `name`=:name WHERE id=:id
$command->update('tbl_user', array(
    'name'=>'Tester',
), 'id=:id', array(':id'=>1));

> **Comments:**
> **username_0**: Thx. It works. It's so easy when you think about it. I'm just a beginner. So there is plenty of practise to do.  

---

