$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();
}
Please check if:
username
really exists. With default Mysql instalation the standard username is root
, not username
.username
has the password password
. In default MYsql installation the user root
has no password set.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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.