Answer the question
In order to leave comments, you need to log in
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;
}
}
}
Answer the question
In order to leave comments, you need to log in
dsn string crooked?
$dsn='musql:
// такой субд нет, есть mysql
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question