Constructor Issue: Db Class Works on Live Website but Fails on Staging Environment

19 Views Asked by At

I'm encountering a perplexing issue with the Dabs class in my WordPress project that has me stumped, and I'm hoping to get some guidance from the community.

The problem revolves around the constructor of the Dabs class in the staging environment, which behaves perfectly fine on the live website but fails to work as expected on the staging environment. Noting that I have 2 Dabs.php file one in staging and the other in the live website. The Dabs class starts as follows:

class Dabs {
    
    // Define variables
    public static $connection;
    private $wpdb;
    
    function __construct() {
        require_once( explode( "wp-content" , __FILE__ )[0] . "wp-load.php" );
        global $wpdb;
        $this->wpdb = $wpdb;
            
    };

In the staging environment, I instantiate the Dabs class from a function named function-A() in my PHP script, which is triggered when the $_SERVER['REQUEST_METHOD'] is set to 'POST'.

Below is the relevant code snippet:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Include required PHP files.
    include_once($_SERVER['DOCUMENT_ROOT'].'/staging/........../Dabs.php');
    // Our database object
    $Dabs = new Dabs();

    // Code goes here

}

I've verified that the path to wp-load.php is correct, and I can confirm that the file does indeed exist in the expected location on the staging environment. Moreover, the Dabs class itself is identical on both the live and staging environments.

Despite these checks, the constructor fails to execute correctly in the staging environment, leading to unexpected behavior and errors throughout the application. I've enabled error reporting and reviewed the server logs, but no errors or warnings seem to be triggered during the constructor's execution.

I would greatly appreciate any insights, suggestions, or debugging tips that could help me uncover the root cause of this discrepancy.

0

There are 0 best solutions below