title: How to debug Codeigniter Fatal Error
body: <p>My Codeigniter 3.0 website, which had been up and running until this morning, had stopped working all of a sudden, showing the following error message on all pages:</p>
  
  <blockquote>
    <p>Fatal error: Call to a member function row() on a non-object in
    /home/[mysite]/public_html/system/libraries/Session/drivers/Session_database_driver.php
    on line 160 </p>
    
    <p>A PHP Error was encountered</p>
    
    <p>Severity: Warning</p>
    
    <p>Message: Cannot modify header information - headers already sent by
    (output started at
    /home/[mysite]/public_html/system/libraries/Session/drivers/Session_database_driver.php:160)</p>
    
    <p>Filename: core/Common.php</p>
    
    <p>Line Number: 569<br>
    A PHP Error was encountered</p>
    
    <p>Severity: Error</p>
    
    <p>Message: Call to a member function row() on a non-object</p>
    
    <p>Filename: drivers/Session_database_driver.php</p>
    
    <p>Line Number: 160</p>
  </blockquote>
  
  <p>Also, the following error messages show up in the <code>error_log</code>: Two memory exhausted messages of two &amp; three days ago (don't know if they're relevant, since the website was functioning well after those, and they only appeared twice), and then lots of the same PHP fatal errors (I copied only three, but there are lots and lots of the same error):</p>
  
  <blockquote>
    <p>[10-Oct-2015 06:04:04 UTC] PHP Fatal error:  Allowed memory size of
    33554432 bytes exhausted (tried to allocate 12 bytes) in
    /home/[mysite]/public_html/system/database/DB_driver.php on line 919</p>
    
    <p>[11-Oct-2015 02:52:43 UTC] PHP Fatal error:  Allowed memory size of
    33554432 bytes exhausted (tried to allocate 32 bytes) in
    /home/[mysite]/public_html/system/database/drivers/mysqli/mysqli_result.php
    on line 168 </p>
    
    <p>[13-Oct-2015 08:25:51 UTC] PHP Fatal error:  Call to a
    member function row() on a non-object in
    /home/[mysite]/public_html/system/libraries/Session/drivers/Session_database_driver.php
    on line 160</p>
    
    <p>[13-Oct-2015 08:26:08 UTC] PHP Fatal error:  Call to a
    member function row() on a non-object in
    /home/[mysite]/public_html/system/libraries/Session/drivers/Session_database_driver.php
    on line 160 </p>
    
    <p>[13-Oct-2015 08:26:17 UTC] PHP Fatal error:  Call to a
    member function row() on a non-object in
    /home/[mysite]/public_html/system/libraries/Session/drivers/Session_database_driver.php
    on line 160</p>
  </blockquote>
  
  <p>Line 160 in <code>Session_database_driver.php</code> is this:</p>
  
  <pre><code>        if (($result = $this-&gt;_db-&gt;get()-&gt;row()) === NULL)
  </code></pre>
  
  <p>and line 569 in <code>core/Common.php</code> is this:</p>
  
  <pre><code>        header($server_protocol.' '.$code.' '.$text, TRUE, $code);
  </code></pre>
  
  <p>This is the function containing the infamous line 160:</p>
  
  <pre><code>public function read($session_id)
      {
          if ($this-&gt;_get_lock($session_id) !== FALSE)
          {
              // Needed by write() to detect session_regenerate_id() calls
              $this-&gt;_session_id = $session_id;
  
              $this-&gt;_db
                  -&gt;select('data')
                  -&gt;from($this-&gt;_config['save_path'])
                  -&gt;where('id', $session_id);
  
              if ($this-&gt;_config['match_ip'])
              {
                  $this-&gt;_db-&gt;where('ip_address', $_SERVER['REMOTE_ADDR']);
              }
  
              if (($result = $this-&gt;_db-&gt;get()-&gt;row()) === NULL)
              {
                  $this-&gt;_fingerprint = md5('');
                  return '';
              }
  
              // PostgreSQL's variant of a BLOB datatype is Bytea, which is a PITA to work with, so we use base64-encoded data in a TEXT field instead.
              $result = ($this-&gt;_platform === 'postgre')
                  ? base64_decode(rtrim($result-&gt;data))
                  : $result-&gt;data;
  
              $this-&gt;_fingerprint = md5($result);
              $this-&gt;_row_exists = TRUE;
              return $result;
          }
  
          $this-&gt;_fingerprint = md5('');
  
          return '';
      }
  </code></pre>
  
  <p>But both of them are the original CI files. I haven't changed anything there.</p>
  
  <p>I have no idea what went wrong and what is causing this, and I have no idea how to start debugging it, since the error messages all point to CI files, not to code that I have written.</p>
  
  <p>Any pointers how to start debugging this would be highly appreciated!</p>