I know questions related to this have been asked a zillion times on Stackoverflow and elsewhere, however, I can't seem to zero in on a resolution.
I am using a nearly fresh-out-of-the-box Macbook 13 running OS 10.13.6 High Sierra.
My goal is to create a development environment with MAMP such that I can create dynamic webpages and I'd like to use Tableau for analytics drawing data out of MySQL.
I have successfully installed and run MAMP - I have created a simple database using phpMyAdmin - and I have connected Tableau to this database successfully - this works very well.
With that in operation, I shifted my attention to trying to run php from my browser. Entering "localhost" yielded the "It works!" result.
All good so far but here is where things go off the rails: I cannot connect to MySQL via a php file using the following (****** = my root password) - filename: test_connect0.php:
<?php
$link = mysqli_connect("localhost", "root", "*****");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL ."<br>";
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL ."<br>";
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL ."<br>";
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
What returns from running Safari or Chrome - doesn't matter - is the familiar issue: 2002 No such file or directory.
BELIEVE ME, I have searched all over the internet for solutions and I believe I have tried each and everyone to no avail.
Here are a few things I have done:
An observation: In item 3 above, I noted that phpInfo from MAMP returns 7.2.1 as the version. When I run a phpinfo() script from the browser, however, it returns 7.1.16. I can't explain why that's a different php version and I cannot even FIND version 7.1.16 on my machine AND I'm not sure any of that really matters.
To summarize, I have a functional MAMP and a functional Tableau connection to MAMP's MySQL. What I can't do is connect to MySQL from a php file run in the browser - I get the 2002 error.
What other information can I provide to help zero in on a solution?
I found the solution:
PHP script fix: Originally, I had my test_connect0.php script in /Library/WebServer/Documents. It turns out, it needs to be in /Applications/MAMP/htdocs. Once I moved the file to that location, I entered this url into the browser: localhost:8888/test_connect0.php
That resulted in a successful connection to MAMP's MySQL.
Tableau notes: As I noted earlier, I was able to connect Tableau to MySQL, however, it wasn't connecting to MAMP's MySQL. To shift Tableau to see MAMP's MySQL, I entered the following into Tableau's dialog:
Server: localhost Port: 8888 Username: root Password: ******
Two things are necessary ahead of time: