Answer the question
In order to leave comments, you need to log in
How to connect to MySQL via PHP 7 on Localhost ("Connection failed: could not find driver" error)?
I installed Apache, PHP 7 on Windows, MySQL was installed, I did not install it. Made basic settings in httpd.conf and php.ini. The extensions in php.ini are all uncommented
The code used is the following. On the hosting https://www.000webhost.com it connects successfully, on the local
host "Connection failed: could not find driver" :
<?php
$servername = "localhost";
$username = "root";
$password = "2523423";
$database = "test1";
try {
$conn = new PDO("mysql:host=$servername;dbname=$database", $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();
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question