I enable mysql service on XAMPP in my windows PC.
No password set into the mysql service, i can connect mysql with MYSQL workbench by
Hostname: localhost
, Port: 3306
and Username: root
but when i try into my php script below
<?php
$servername = "localhost";
$username = "root";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username);
// 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();
}
?>
It gives me Connection failed
. What is problem?