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

PHP

Adam Siwiec
Adam Siwiec
12,070 Points

PDO connection is not working, but mysql_connect is? What's up!

This code cant connect to my remote database:

$db = new PDO("mysql:host=107.170.88.209;dbname=my_first_database;port=3306",aUsername,aPassword);

but this can:

mysql_connect('107.170.88.209', aUsername, aPassword);

What am I doing wrong?

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

Is your database name correct, and does it already exist? (If it doesn't exist you can try omitting the database name and execute a "CREATE DATABASE ..." query followed by a "USE ...".)

Peter Hatzer
Peter Hatzer
20,837 Points

Hi Adam, you mysql:host should be mysql:host=localhost