The situation is this, I am trying to use a PHP connection to connect my MySQL Database which is on phpmyadmin. Nothing fancy about the connection just trying to see whether the connection is successful or not. I am using MAMP to host the database, the connection I am trying to use is this:
$servername = "127.0.0.1";
$username = "root";
$password = "root";
$conn = new PDO("mysql:host=$servername;dbname=AppDatabase", $username, $password);
// set the PDO error mode to exception
echo "Connected successfully";
echo "Connection failed: " . $e->getMessage();
I found the reason why the connection was not working, it was because the connection was trying to connect to port 8888, when it needed to connect to port 8889.
$conn = new PDO("mysql:host=$servername;port=8889;dbname=AppDatabase", $username, $password);
This fixed the problem, although changing the server name to localhost still gives the error.
Connection failed: SQLSTATE[HY000]  No such file or directory
But it connects successfully when the IP address is entered for the server name.