Unable to connect to database using configuration file

I use a file ( ss-config.php) that contains information about connecting a servo motor and a database, here is the file code ss-config.php:

<?php

define('DB_NAME', 'ssiphone');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', '');

/** MySQL hostname */
define('DB_HOST', 'localhost');
?>

but when I try to connect, I got this error:

Parse error: parse error in C:\wamp\www\ssiphone\classes\ConnectionManipulationBaseDeDonnees.php on line 21

this is my code that would suggest causing the problem:

class ConnectionManipulationBaseDeDonnees
{
   private $bdd;//attribut $bdd qui contiendra la connexion Γ  la base 


   public function connection(){//fonction connection qui se charge de la connexion Γ  la base de donnΓ©es
   include("../ssiphoneadmin/ss-config.php");
         $host=DB_HOST;
         $dbname=DB_NAME;
         $dbuser=DB_USER;
         $dbpsw=DB_PASSWORD;

         try{
            $pdo_options[PDO::ATTR_ERRMODE]=PDO::ERRMODE_EXCEPTION;

            $this->bdd=new PDO('mysql:host='.$host.';dbname='.$dbname.','.$dbuser.','.$dbpsw.','$pdo_options);
            }
         catch(Exception $e)//en cas d`erreur, le catch est fait pour la rattrapper 
            {
            die('Erreur: '.$e->getMessage());
            }
   }//fin fonction connection
}//fin class

line 21 is the line containing the statement $this. thanks for any help :)

+3
source share
4 answers

I think the PDO constructor should look like this:

$this->bdd=new PDO('mysql:host='.$host.';dbname='.$dbname, $dbuser, $dbpsw, $pdo_options);

as stated in the documentation:

PDO::__construct() ( string $dsn [, string $username [, string $password [, array $driver_options ]]] )
0
source
     $this->bdd=new(PDO('mysql:host='.$host.'dbname='.$dbname.','.$dbuser.','.$dbpsw.','$pdo_options);
                                                                                      ^^^

You are missing .in the place that I indicated.

0
source

. ($pdo_options).

$this->bdd=new PDO('mysql:host='.$host.';dbname='.$dbname.','.$dbuser.','.$dbpsw.','.$pdo_options);
                                                                                    ^
                                                                                    |
                                                                                    |
0

.

$this->bdd=new PDO('mysql:host='.$host.';dbname='.$dbname.','.$dbuser.','.$dbpsw.','$pdo_options);

$this->bdd=new PDO('mysql:host='.$host.';dbname='.$dbname.','.$dbuser.','.$dbpsw.','.$pdo_options);
0

All Articles