I have written a basic MySQL database connection code in PHP (5.5), which runs fine as a PHP script but the same script when run from Apache(2.4) gives the error “Connection failed: could not find driver”
try {
$conn = new PDO(“mysql:host=$servername;dbname=db”, “username”, “password”);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo “Connected successfully using PDO”;
}catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}