Development Tools Using PHP with MySQL Connecting PHP to MySQL Getting Started with PDO

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 Points

Hello, I am not able to render database.php in my Chrome browser using my Mac

First attempt URL: file://localhost/Users/ckom9/Documents/Treehouse/Using_PHP_with_MySQL/htdocs/database.php The above will display my php source code, not web page.

Second attempt URL: localhost/Users/ckom9/Documents/Treehouse/Using_PHP_with_MySQL/htdocs/database.php This second attempt will fails with "web page not available".

I have commented out line with $db = new PDO(). So this is just a question about rendering a php web page on a browser using a Mac. Thank all for any assistance.

3 Answers

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 Points

Yes, using MAMP as described in the earlier video works for me. Not really sure what problem is, but this should work out fine.

That's great to hear, thanks for providing an update! Congratulations on getting that setup :)

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 Points

P.S. here is complete code for database.php:

<?php

echo "Woo-hoo!";

?>

Hi Chris,

I get the first error, displaying php source code, when a server isn't running. If your server is running - I'm not sure. Has this worked for you before, or is this the first time trying?

Chris Komaroff
PRO
Chris Komaroff
Pro Student 13,666 Points

Hi Robert, MySQL server is running, I checked again. I have been running php code in a html editor called Taco, but it may have a problem, so I want to run php script in Chrome. I went through intro to db using MySQL Workbench, but maybe I need to use MAMP as client in order to do the php with mysql course. But I think this may be very basic question about how to actually run php code (not containing any sql) locally in a browser.

Unfortunately I have zero experience with Mac, but I can infer that MAMP may indeed solve the problem. A MySQL server, alone, would not be able to interpret and serve php code - that I'm aware of. It's Apache, the A in MAMP, that performs this job.

Hope this helps in some way.

Cheers