Quantcast
Channel: WampServer - WampServer English
Viewing all articles
Browse latest Browse all 3177

UNABLE TO CONNET TO MySQL DATABASE (3 replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 3177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>