I am using:
Wampserer 3.0.4,
PHP 5.6.19,
Apache 2.4.18, Port 80,and
MySQL 5.7 11.
I was trying to open a connection to MySQL database using PDO with the following code but received this
error message: "Connection failed: SQLSTATE[HY000][1049] Unknown database 'myDB'. I have checked and
rechecked to find out my mistake to no avail, and should be grateful for any assistance to fish out the error
because I specified dbname here:
" $conn = new PDO("mysql:host=$servername;dbname=myDB", "root", "patony");"
<!DOCTYPE html>
<html lang="en-us">
<meta charset="utf-8">
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "patony";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", "root", "patony");
//Set the PDO error mode to exception
$conn->Attribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
</body>
</html>
Thanks
Wampserer 3.0.4,
PHP 5.6.19,
Apache 2.4.18, Port 80,and
MySQL 5.7 11.
I was trying to open a connection to MySQL database using PDO with the following code but received this
error message: "Connection failed: SQLSTATE[HY000][1049] Unknown database 'myDB'. I have checked and
rechecked to find out my mistake to no avail, and should be grateful for any assistance to fish out the error
because I specified dbname here:
" $conn = new PDO("mysql:host=$servername;dbname=myDB", "root", "patony");"
<!DOCTYPE html>
<html lang="en-us">
<meta charset="utf-8">
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "patony";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", "root", "patony");
//Set the PDO error mode to exception
$conn->Attribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
</body>
</html>
Thanks