0

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.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
19Syntax
  • 9
  • 3
  • Are they running different versions of PHP? – Nigel Ren May 31 '21 at 15:41
  • that was my first idea but all domains running PHP 7-3. – 19Syntax May 31 '21 at 15:43
  • The use of `global` in class functions isn't good practice. I also wonder if you are expecting the method `global_class` tor be called in the class of the same name. This probably should be the `__construct` method (https://stackoverflow.com/questions/455910/what-is-the-function-construct-used-for). – Nigel Ren May 31 '21 at 15:49
  • i know but this is not the reason for the actual problem ;) – 19Syntax May 31 '21 at 17:47
  • any other help? I finished this project now after 7 Month working... i really need to get this run now :/ – 19Syntax May 31 '21 at 20:55

0 Answers0