Note that there are some explanatory texts on larger screens.

plurals
  1. POFatal error: Call to a member function fetch() on a non-object on old php 5.1 code now running on php 5.4
    text
    copied!<p>I have this old code that was written around the time of PHP 5.1, I am trying to make it all work on a newer server running php5.4 however I am getting this error from the code below:</p> <p>Fatal error: Call to a member function fetch() on a non-object</p> <pre><code>&lt;?php /** * &lt;b&gt;Database Connection&lt;/b&gt; class. * @author Php Object Generator * @version 3.0 / PHP5.1 * @see http://www.phpobjectgenerator.com/ * @copyright Free for personal &amp; commercial use. (Offered under the BSD license) */ Class Database { private function Database() { $databaseName = $GLOBALS['configuration']['db']; $driver = $GLOBALS['configuration']['pdoDriver']; $serverName = $GLOBALS['configuration']['host']; $databaseUser = $GLOBALS['configuration']['user']; $databasePassword = $GLOBALS['configuration']['pass']; $databasePort = $GLOBALS['configuration']['port']; $databaseName = 'bitbsoft_butlers'; $driver = $GLOBALS['configuration']['pdoDriver']; $serverName = 'localhost'; $databaseUser = 'bitbsoft_butlers'; $databasePassword = 'Sherw00d123'; $databasePort = '3306'; if (!isset($this-&gt;connection)) { $this-&gt;connection = new PDO($driver.':host='.$serverName.';port='.$databasePort.';dbname='.$databaseName, $databaseUser, $databasePassword); $this-&gt;connection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } if (!$this-&gt;connection) { throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.'); } } public static function Connect() { static $database = null; if (!isset($database)) { $database = new Database(); } return $database-&gt;connection; } public static function Reader($query, $connection) { try { $result = $connection-&gt;Query($query); } catch(PDOException $e) { return false; } return $result; } public static function Read($result) { try { return $result-&gt;fetch(); } catch (PDOException $e) { return false; } } public static function NonQuery($query, $connection) { try { $r = $connection-&gt;query($query); if ($r === false) { return 0; } return $r-&gt;rowCount(); } catch (PDOException $e) { return false; } } public static function Query($query, $connection) { try { $i = 0; $r = $connection-&gt;query($query); foreach ($r as $row) { $i++; } return $i; } catch (PDOException $e) { return false; } } public static function InsertOrUpdate($query, $connection) { try { $r = $connection-&gt;query($query); return $connection-&gt;lastInsertId(); } catch (PDOException $e) { return false; } } } ?&gt; </code></pre> <p>Now the error is being thrown by the line fetch() but I am confused as to what has changed from 5.1 to 5.4 that would cause this, would really appreciate any help on this.</p> <p>Many thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload