i have some Webprojekt that all has the same code to connect with mysql. The actual project works fine on local (xampp) now. So i uploaded it to my webserver and changed all required datas like sql connection and filepath. Now and ONLY on the webserver i got this error:
Fatal error: Uncaught Error: Call to a member function query() on null in /kunden/fewo/includes/class_db_handle.php:34 Stack trace: #0 /kunden/fewo/includes/functions_global.php(33): db_handle->direct_query('SELECT * FROM x...') #1 /kunden/fewo/includes/functions_global.php(14): global_class->loadsettings() #2 /kunden/fewo/common.php(37): global_class->global_class() #3 /kunden/fewo/index.php(2): include('/kunden/...') #4 {main} thrown in /kunden/fewo/includes/class_db_handle.php on line 34
class_db_handle.php start line 31:
class db_handle
{
// database
private $pdo;
private $DBPrefix;
private $CHARSET;
private $lastquery;
private $fetchquery;
private $error;
public $PDOerror;
public function connect($DbHost, $DbUser, $DbPassword, $DbDatabase, $DBPrefix, $CHARSET)
{
$this->DBPrefix = $DBPrefix;
$this->CHARSET = $CHARSET;
try {
// MySQL with PDO_MYSQL
$this->pdo = new PDO("mysql:host=$DbHost;dbname=$DbDatabase;charset =$CHARSET", $DbUser, $DbPassword);
// set error reporting up
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// actually use prepared statements
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch(PDOException $e) {
$this->error_handler($e->getMessage());
}
}
// to run a direct query
public function direct_query($query)
{
try {
$this->lastquery = $this->pdo->query($query);
}
catch(PDOException $e) {
$this->error_handler($e->getMessage());
}
}
functions_global.php:
class global_class
{
var $SETTINGS, $ctime, $tdiff, $counters;
function global_class()
{
global $DBPrefix, $MSG, $db;
// Load settings
$this->loadsettings();
//setting up the time and date with dst
if(date('I') == 1)
{
$this->ctime = time() + 3600 * ($this->SETTINGS['timecorrection'] + date('I'));
}
elseif(date('I') == 0)
{
$this->ctime = time() + 3600 * $this->SETTINGS['timecorrection'];
}
$this->tdiff = ($this->SETTINGS['timecorrection'] + date('I'));
}
function loadsettings()
{
global $DBPrefix, $db;
$query = "SELECT * FROM " . $DBPrefix . "settings";
$db->direct_query($query);
$this->SETTINGS = $db->result();
if ($this->SETTINGS['https'] == 'y')
{
$full_url = 'https://' . $this->SETTINGS['siteurl'];
}
else
{
$full_url = 'http://' . $this->SETTINGS['siteurl'];
}
$this->SETTINGS['siteurl'] = $full_url;
//load google adsense
$this->loadadsense();
//load counters db
$this->counterdb();
}
common.php where all begins:
// SQL classes
include $include_path . 'class_db_handle.php';
$db = new db_handle();
// connect to the database
if (isset($CHARSET)) {
$db->connect($DbHost, $DbUser, $DbPassword, $DbDatabase, $DBPrefix, $CHARSET);
}else{
$db->connect($DbHost, $DbUser, $DbPassword, $DbDatabase, $DBPrefix, 'UTF-8');
}
// classes
include $include_path . 'functions_global.php';
$system = new global_class();
As is said, it works finde in other projects and it works on local server. After upload i got trouble with it.