title: In yii how to write insert query
body: <p>In yii, I am creating login module. After successful login I have to retrieve current login users userid and want to insert that userid into another 'logintransLog' table which is having userid as attribute with foreign key relationship. So in yii, how to retrieve current userid and insert it into another table? Please help me.....</p>
  
  <hr>
  
  <p>I want to insert userid into table 'loginAttempt' if only userid is correct and password is wrong, in order to maintain records of how much time user had tried for login. So how can I implement this? I have actionlogin method as:  </p>
  
  <pre><code>public function actionLogin()
  {
      $model=new LoginForm;
      $command = Yii::app()-&gt;db-&gt;createCommand();
  
      // if it is ajax validation request
      if(isset($_POST['ajax']) &amp;&amp; $_POST['ajax']==='login-form')
      {
          echo CActiveForm::validate($model);
          Yii::app()-&gt;end();
      }
  
      // collect user input data
      if(isset($_POST['LoginForm']))
      {
          $model-&gt;attributes=$_POST['LoginForm'];
          // validate user input and redirect to the previous page if valid
          if($model-&gt;validate() &amp;&amp; $model-&gt;login())
          {
                  $command-&gt;insert('trans', array(
                      'id'=&gt;Yii::app()-&gt;user-&gt;getId(),
                  //'Ipaddress'=&gt;Yii::app()-&gt;user-&gt;getIpaddress(),
                  ));
              $this-&gt;redirect(Yii::app()-&gt;user-&gt;returnUrl);
          }
  
      }
      // display the login form
      $this-&gt;render('login',array('model'=&gt;$model));
  }      
  </code></pre>
  
  <p>Please help me</p>