I am trying to connect to a database but getting the error message saying:
PDOException: could not find driver in E:\Drive\Dev\PHP\connect\index.php:3 Stack trace: #0 E:\Drive\Dev\PHP\connect\index.php(3): PDO->__construct('mysql:host=localhost;...', 'dbuser', 'dbpassword') #1 {main}
I use XAMPP to run Apache and MySQL. Also I have configured VirtualPorts and accessing all websites by their aliases e.g. 'mysite/' instead 'localhost'
Could you kindly check the code below and help me to solve the issue. Thanks in advance!
<?php
try{
$pdo = new PDO('mysql:host=localhost;dbname=carbrands', 'dbuser', 'dbpassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch(PDOException $e){
$output = 'not connected';
$e->getMessage();
include 'output.html';
exit();
}
$output = 'connected';
include 'output.html';
?>