SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pdo error: Error connecting: could not find driver

    I am new to php and mysql. I am running Apache 2.2.25, PHP 5.4.22, and MySql 5.1.72 on Windows 7 64 bit.

    This code generates the error: Error connecting: could not find driver

    <?php

    ini_set('display_errors',1);
    error_reporting(E_ALL);

    try
    {
    $pdo = new PDO('mysql:host=localhost;dbname=my_contacts','root','password');
    }
    catch (PDOException $e)
    {
    $output = 'Error connecting: ' . $e->getMessage();
    exit();
    }

    echo 'Connected to MySql<br>';

    Obviously I need to install or configure something, but I'm to sure where to look.


    Thanks for any insight or ideas on this!
    Robin

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,368
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    It is helpful to put your code into php tags; they are not available on the quick reply but you have to go to the advanced reply section.

    As you guessed you need to enable or install a MySQL driver; are you sure pdo is available to you?

    I would check out the php manual

    You can confirm pdo is available using:

    PHP Code:
    // Is PDO installed?
    if (!defined('PDO::ATTR_DRIVER_NAME')) {
    echo 
    'PDO is unavailable<br/>';
    }
    elseif (
    defined('PDO::ATTR_DRIVER_NAME')) {
    echo 
    'PDO is available<br/>';


  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    I solved it, I found this line in the php.ini file and "uncommented" it. now pdo works!
    ;extension=php_pdo_mysql.dll


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •