0

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';
?>
egurb
  • 1,176
  • 2
  • 14
  • 40

1 Answers1

0

Looks like you are missing the correct driver.

Check this answer, as it might help you

Missing driver

Community
  • 1
  • 1
MacGyer
  • 198
  • 1
  • 6
  • Yep, thanks! I could not figure out from the first time I read the article. Now it works :) – egurb Apr 08 '16 at 22:35