title: Codeigniter Showing database error when redirected from facebook login
body: <p>I'm trying to create facebook login,</p>
  
  <p>Login button on my site redirect me to facebook, for login, ask to permit my application for required permission ('offline_access,email etc').</p>
  
  <p>When user allow it returns to my inside page(User Page). Also add the user data to my database if user's facebook id is not in my database.</p>
  
  <p>but it is not working every time (in both case if user in database or not). sometime it gives following error:</p>
  
  <pre><code>A Database Error Occurred
  
  Unable to connect to your database server using the provided settings.
  
  Filename: core/Loader.php
  
  Line Number: 346
  </code></pre>
  
  <p>This is my login function which generate the fb login url</p>
  
  <pre><code>$this-&gt;load-&gt;library('facebook');
          $user = $this-&gt;facebook-&gt;getUser();
          $data['loginUrl']="";
          $data['logoutUrl']="";
          if ($user) {
              try {
                  $data['user_profile'] = $this-&gt;facebook-&gt;api('/me');
              } catch (FacebookApiException $e) {
                  error_log($e);
                  $user = null;
              }
          }
          if ($user) {
              $data['logoutUrl'] = $this-&gt;facebook-&gt;getLogoutUrl(array(
                  'next' =&gt; ASITEURL . '/login/logout'));
          } else {
              $param['redirect_uri'] = ASITEURL . '/login/checkLogInfo';
              $param['scope'] = 'email,publish_stream,user_birthday';
              $data['loginUrl'] = $this-&gt;facebook-&gt;getLoginUrl($param);
          }
          $this-&gt;load-&gt;view('login/login', $data);
  </code></pre>
  
  <p>checkLogInfo is function which handles the session and database code.</p>
  
  <p>Fb Redirect me to following url after successful login (and granting permission first time):</p>
  
  <pre><code>http://mysite.com/login/checkLogInfo?state=4d59a4fe681ae940f036393c895d1c57&amp;code=AQA3gAnl86izonBQyh8wThjNZuNowX1h6YBlGkeIiaQU__DFHDywC9nIgWYzW22EaxkVJB5nudjnNd4uElNs1-SFa0Ej_h4_4AAaYh4bLf9_HBpUiaSzbuDUcYg0WIIg0B4mvKq0_H3W3xH0gcKPWL1Fbrp3ff3IVt0unFIIeyevRb9oZwPld6NTKtU_tHxrQFtEdMgE6S2dwPcrbyY54g82#_=_
  </code></pre>
  
  <p>Database Setting :</p>
  
  <pre><code>    $db['default']['hostname'] = 'localhost';
      $db['default']['username'] = 'root';
      $db['default']['password'] = '';
      $active_group = 'default';
      $active_record = TRUE;
  
  $db['default']['database'] = 'mydb';
      $db['default']['dbdriver'] = 'mysql';
      $db['default']['dbprefix'] = '';
      $db['default']['pconnect'] = FALSE;
      $db['default']['db_debug'] = TRUE;
      $db['default']['cache_on'] = FALSE;
      $db['default']['cachedir'] = '';
      $db['default']['char_set'] = 'utf8';
      $db['default']['dbcollat'] = 'utf8_general_ci';
      $db['default']['swap_pre'] = '';
      $db['default']['autoinit'] = TRUE;
      $db['default']['stricton'] = FALSE;
  </code></pre>
  
  <p>Thanks </p>