-1

I am writing a DAO class to connect to SQL Server database. I have this error that I don't know how to fix it. My code :

class DAO
      {
        // @var PDO : Attribut représentant la base de données 
        private $db;

        // Connexion à la BDD 
        function __construct()
        {
            try {
              $dsn = '192.168.102.232\SQLEXPRESS' 
              $this->db = new PDO("sqlsrv:Server=192.168.102.232\SQLEXPRESS;Database=PROFACE", "username", "pwd");
              $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch (PDOException $e) {
              exit("Cannot open DB : ".utf8_encode($e->getMessage()));
            }
          }
        }
      }

And the error : Parse error: syntax error, unexpected '$this' (T_VARIABLE) in C:\wamp\www\WebJM\AffichageHistorique\db\database.php

MissKnacki
  • 269
  • 4
  • 15

1 Answers1

0

There is a missing ; on $dsn = '192.168.102.232\SQLEXPRESS' row.

Try the following:

class DAO
      {
        // @var PDO : Attribut représentant la base de données 
        private $db;

        // Connexion à la BDD 
        function __construct()
        {
            try {
              $dsn = '192.168.102.232\SQLEXPRESS';
              $this->db = new PDO("sqlsrv:Server=192.168.102.232\SQLEXPRESS;Database=PROFACE", "username", "pwd");
              $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch (PDOException $e) {
              exit("Cannot open DB : ".utf8_encode($e->getMessage()));
            }
          }
        }
      }
Martin Dimitrov
  • 1,304
  • 1
  • 11
  • 25