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 trialMarcel Neuenhaus
723 PointsConnecting 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
13,860 PointsTry leaving the password blank?
Arthur Verschaeve
20,816 PointsThe errors you're getting are about the include statement for inc/products.php, not really about the PHP-MySQL connection, I think.
Marcel Neuenhaus
723 PointsOkay, but how can I solve it? The include statement was in the project files and I havn't changed anything?
Arthur Verschaeve
20,816 PointsThink 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
Marcel Neuenhaus
723 PointsThat'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?
Arthur Verschaeve
20,816 PointsHave 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.
Marcel Neuenhaus
723 PointsYes I have, here is another Screenshot: http://www.directupload.net/file/d/3655/eytufqi5_png.htm and I work with XAMPP.
Arthur Verschaeve
20,816 PointsIn 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;)
Marcel Neuenhaus
723 PointsI 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)
Arthur Verschaeve
20,816 PointsI 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?
Marcel Neuenhaus
723 PointsIt throws: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) Why is it denied, or what should I do now?
Marcel Neuenhaus
723 PointsIt worked, thank you.. That was too easy
Ralph Breno
31 PointsHi. 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.