I’m trying to use this to connect to my DB:
<?php
$servername = "localhost";
$username = "root";
$password = "{hidden}";
try {
$conn = new PDO("mysql:host=$servername;dbname=testdb", $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();
}
?>
but I’m getting the connection failure error:
Connection failed: SQLSTATE[HY000] [2002] No such file or directory
What am I doing wrong?