PHP using PDO

when running CLASS_Database.php , from the address bar

i have

Parse error : syntax error, unexpected ‘(’ in /home2/glanglais57/public_html/directory/includes/class_database.php on line 337

I have trouble to fix the Parse error.

I will appreciate help.
Thank’s in advance

335- function Connect($host, $user, $pass, $name, $type =
‘mysql’) {
336- PDO;
337- $this->connection = new ( ‘’ . $type . ‘:host=’ . $host .
‘;dbname=’ . $name, $user, $pass );
}

Not really sure what this class is all doing?

The whole syntax looks to be off as well? The odd single quotes… as well as your params out of order?

Not sure what the PDO; line does either (although could be legit? just not how I do things I guess?)

Maybe this helps:

$this->connection = new ($type.':host=' . $host . ';dbname=' . $user, $pass, $name);

I dont use a class of a function…

I often have my included DB connection file like so:

try{
	$dbhost = 'localhost';
	$dbname = 'test';
	$dbuser = 'root';
	$dbpass = '';
	$conn = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname, $dbuser, $dbpass);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e) {  
	echo $e->getMessage();  
}

Thank’s Whispers , for your comments. I will try your suggestion. The class id taking care or sql connection and PDO connection. I am not an expert and i have trouble to get access to my backend as i use to be and this is since update of php 7 , i am looking for help???
getting access to my admin back office to manage wordpress is fine but it is when i try the public_html/directory/cp/index that nothing happen else than error like
Deprecated : Non-static method Registry::getInstance() should not be called statically in /home2/glangl7/public_html/RESSOURCESSINESVILLEDEQUEBEC.COM/directory/defaults_setup.php on line 242

Not seeing the code I’m unsure, but the following might work?

// Get an instance of the Database.
// @return Database:
protected static function getInstance(): Database
{
    if (!self::$_instance) {
        self::$_instance = new self();
    }
    return self::$_instance;
}

public static function pdo(): PDO
{
    $db = static::getInstance();
    return $db->getConnection();
}

// Empty clone magic method to prevent duplication:
private function __clone() {

}

// Get the PDO connection:
protected function getConnection(): PDO
{
    // This is where you grab the connection
    // from the __construct()
    return $this->_connection; 
}

I’m using php 8.0 so :Database & : PDO might have to be remove for earlier versions.

Thank’s Strider64 , i am taking note

Sponsor our Newsletter | Privacy Policy | Terms of Service