So I have a PDO Connection set up in PHP and I can access the database I am trying to connect to within navicat, but can't code wise. Should mention that the database is within vagrant alongside the code itself.
If I use localhost in the servername then I get file not found within the connection and with 127.0.0.1, I receive the error of connection refused so am not too sure what is causing the issue, because most people said it was the port which I have declared too.
The PDO Connection
$servername = "127.0.0.1";
$username = "root";
$password = "secret";
try {
$conn = new PDO("mysql:host=$servername;port=3306;dbname=staff_members", $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();
}