Unable To Connect To Database - PHP
<p>I am trying to connect to a database but getting the error message saying:</p>

<pre><code>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-&gt;__construct('mysql:host=localhost;...', 'dbuser', 'dbpassword') #1 {main}
</code></pre>

<p>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'</p>

<p>Could you kindly check the code below and help me to solve the issue. Thanks in advance!</p>

<pre><code>&lt;?php
    try{
        $pdo = new PDO('mysql:host=localhost;dbname=carbrands', 'dbuser', 'dbpassword');
        $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo-&gt;exec('SET NAMES "utf8"');
    }
    catch(PDOException $e){
        $output = 'not connected';
        $e-&gt;getMessage();
        include 'output.html';
        exit();
    }

    $output = 'connected';
    include 'output.html';
?&gt;
</code></pre>