I am trying to connect MySQL Database which is on PHPMyAdmin.using PHP. I am using MAMP to host the database, the connection I am trying to use is this:
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "root";
try {
$conn = new PDO("mysql:host=$servername;dbname=AppDatabase", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
I keep receiving this error when I try to test if the connection is working or not using postman:
Connection failed: SQLSTATE[HY000] [2002] Connection refused
How can I make this work?