N
N
netrox2018-02-01 21:55:43
PHP
netrox, 2018-02-01 21:55:43

Why is an exception thrown when creating a PDO instance?

When creating a PDO instance, an exception is thrown: "could not find driver".
The code:

class Database
  {
    private $host=DB_HOST;
    private $user=DB_USER;
    private $pass=DB_PASS;
    private $dbname=DB_NAME;

    private $dbh; //Database handler (for PDO)
    private $stmt;
    private $error;
    public function __construct()
    {
      $dsn='musql:host='.$this->host.';dbname='.$this->dbname;
      $options=[PDO::ATTR_PERSISTENT=>true,PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION];

      try
      {
        $this->dbh=new PDO($dsn,$this->user,$this->pass,$options);

      }
      catch (PDOException $e)
      {
        $this->error=$e->getMessage();
        echo $this->error;
      }
    }
  }

5a73629d0be96732726236.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman PHP, 2018-02-01
@netrox

dsn string crooked?

$dsn='musql:

// такой субд нет, есть mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question