SitePoint Sponsor

User Tag List

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

    Trouble connecting to MySQL database using PHP

    Hello,

    I running through some exercises in the sitepoint book "PHP and MySQL: Novice to Ninja" (Chapter 4/connect/index.php). I opted to install PHP and MySQL separately instead of using XAMPP. I'm running on Windows 7, MySQL Server is 5.5, and PHP is (I think) 5.4.6. Web server is Apache 2.4.

    I'm creating a connection using the following:

    PHP Code:
    try
    {
      
    $pdo = new PDO('mysql:host=localhost;dbname=ijdb''ijdbuser''mypassword');
      
    $pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
      
    $pdo->exec('SET NAMES "utf8"');
    }
    catch (
    PDOException $e)
    {
      
    $output 'Unable to connect to the database server: ' .
        
    $e->getMessage();
      include 
    'output.html.php';
      exit();
    }

    $output 'Database connection established.';
    include 
    'output.html.php'


    When running I get "Unable to connect to the database server: could not find driver"

    I've been enjoying the book so far and was cruisin' along until now. Any help would be appreciated. Am I missing a PHP module or something?

    Thanks.

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,195
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    I have never used it but looking at pdo installation it says:
    You may need to enable the PDO driver for your database of choice; consult the documentation for database-specific PDO drivers to find out more about that.

  3. #3
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    I have never used it but looking at pdo installation it says:
    Thanks! The information in the link you provided worked. I had to enable the following in the php.ini file:

    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
  •