title: codeigniter google login with existing gmail account creating duplicate row
body: <p>I have implemented google login in existing user table in coeigniter. User can login whether with existing email and password or from google login. Everything working fine but i need to check with existing email. Suppose that gmail already in the database i need to update the oauth_provider and oauth_uid in the existing row. Right now creating new row for google login. So my emails are  duplicated.</p>
  <p>public function checkUser($data = array()){</p>
  <pre><code>    $this-&gt;db-&gt;select('id');
      $this-&gt;db-&gt;from($this-&gt;tableName);
      
      $con = array(
          'oauth_provider' =&gt; $data['oauth_provider'],
          'oauth_uid' =&gt; $data['oauth_uid']
      );
      $this-&gt;db-&gt;where($con);
      $query = $this-&gt;db-&gt;get();
  
      //echo $this-&gt;db-&gt;last_query(); die;
      
      $check = $query-&gt;num_rows();
      if($check &gt; 0){
          // Get prev user data
    $result = $query-&gt;row_array();
          
          
          // Update user data
          $data['edited_dt'] = date(&quot;Y-m-d H:i:s&quot;);
          $update = $this-&gt;db-&gt;update($this-&gt;tableName, $data, array('id' =&gt; $result['id']));
          
          // Get user ID
          $userID = $result['id'];
      }else{
          // Insert user data
          $data['created_dt'] = date(&quot;Y-m-d H:i:s&quot;);
          $data['edited_dt'] = date(&quot;Y-m-d H:i:s&quot;);
          $insert = $this-&gt;db-&gt;insert($this-&gt;tableName, $data);
          
          // Get user ID
          $userID = $this-&gt;db-&gt;insert_id();
      }
      
      // Return user ID
      return $userID?$userID:false;
  }
  </code></pre>