Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

PHP Mysql - Connection problems

Hello everybody,

I am using Wamp Server and Xampp, i am not able to connect to database using dreamweaver.

Can someone please give me assistance to enable me follow the PHP Training videos.

3 Answers

Hi Harrison, What you mean you can't connect to database?? Do you mean from your script ?? if thats the case then mostly database-user is root and password is "" or empty.. that's the default configuration . hope that helps

Thanks Ali, i think i got the db user & password correctly. connecting to database codes on the below using PDO stuffs is giving me error messages, link http://treehouse-code-samples.s3.amazonaws.com/php_mysql/shirts4mike.sql

Please do you have any idea how i can connect to it successfully?

I am sorry I have no clue as what are you asking about ?? the file that you have mentioned here and its a sql file ? if you can explain as what you want to do then i might be able to help...

The sql file is there for you to import it onto your database and that will create the table and also enter the relevant information. then you can connect to the database and retrieve this information ..

Thanks for offering your assistance, i actually i have been able create the database and table using the mysql code.

The challenges now is i can't connect to the database and tables created.

I am using Dreamweaver & notepad++

Any idea for me please?

<?php
  $user = your username mostly root in case of xampp
 $password = your password mostly empty in case of xampp unless you have changed it
try {
    $dbh = new PDO('mysql:host=localhost;dbname=databaseName', $user, $pass);
    foreach($dbh->query('SELECT * from products') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>

run that and lets see if it works or not

Make sure you replace database name with the name of your database