$servername= "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=testing",$username, $password);
//set the PDO error mode exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "connected successfully";
} catch(PDOException $e) {
echo " connection failed: " . $e->getMessage();
}
CodePudding user response:
Please check if:
- user with username
username
really exists. With default Mysql instalation the standard username isroot
, notusername
. - the user with
username
has the passwordpassword
. In default MYsql installation the userroot
has no password set.
CodePudding user response:
Check via commandline whether you can connect to your database: https://dev.mysql.com/doc/refman/8.0/en/connecting.html
mysql --host=localhost --user=myname --password=password mydb
I believe you are not knowing your credentials to access the database... How did you install the MySQL database?