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 Using PHP with MySQL Connecting PHP to MySQL Getting Started with PDO

Connecting PHP to MySQL

Hello,

I need help with the integration of PHP to MySQL. Every time a connection is not added to the database. Even if I copy the project files and adding, no connection can be established. Another test showed that invokes the index.php the following error message call:

Warning: include (C :/ xampp / htdocs / inc / products.php): failed to open stream: No such file or directory in C: \ xampp \ htdocs \ mike \ index.php on line 4

Warning: include (): Failed opening 'C :/ xampp / htdocs / inc / products.php' for inclusion (include_path = '; C:. \ Xampp \ php \ PEAR') in C: \ xampp \ htdocs \ mike \ index.php on line 4

Fatal error: Call to undefined function get_products_recent () in C: \ xampp \ htdocs \ mike \ index.php on line 5

I have copied all the files, start XAMPP and it works not yet

10 Answers

Chris Curtis
Chris Curtis
13,860 Points

Try leaving the password blank?

The errors you're getting are about the include statement for inc/products.php, not really about the PHP-MySQL connection, I think.

Okay, but how can I solve it? The include statement was in the project files and I havn't changed anything?

Think you have copied the 'mike' folder into your htdocs. But that isn't correct. The files that are inside of your 'mike' folder have to be directly in your htdocs and not inside of the mike folder

That's right, I have copied the 'mike' folder into htdocs. Thanks for the solution, it works!

But there is still the database connection that don't work. Here is a screenshot: http://www.directupload.net/file/d/3655/5bbi4igm_png.htm Do you have an idea, how to solve it?

Have you created the shirts4mike database?

Are you using the correct username and password for the mysql connection? Not sure but I think the default username is root and the default pass is root too in XAMPP. If your are working with MAMP you don't need a pass.

Yes I have, here is another Screenshot: http://www.directupload.net/file/d/3655/eytufqi5_png.htm and I work with XAMPP.

In debugging, it can be handy to throw the error on the screen...

Maybe try echoing out $e->getMessage(); in your catch block. (just before the exit;)

I see... It doesen't work, too. I like to get that: object(PDO)#1 (0) { } on the browser like here http://teamtreehouse.com/library/using-php-with-mysql/connecting-php-to-mysql/handling-exceptions-2 (min 3:05)

I know you want to have that result... Simply for debugging it's handy to echo out $e->getMessage();

If you are echoing that, what do it throws you?

It throws: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) Why is it denied, or what should I do now?

It worked, thank you.. That was too easy

Hi. I have the same error. Warning: include (C :/ xampp / htdocs / inc / products.php): failed to open stream: No such file or directory in C: \ xampp \ htdocs \ project \ index.php on line 4

Warning: include (): Failed opening 'C :/ xampp / htdocs / inc / products.php' for inclusion (include_path = '; C:. \ Xampp \ php \ PEAR') in C: \ xampp \ htdocs \ projectmike \ index.php on line 4

I copied the files but I am still getting the same error.