MySQL Forums
Forum List  »  PHP

unable to open mysql database using pdp
Posted by: Patrick Onyilimba
Date: September 09, 2016 12:21AM

I was trying to open a connection to MySQL and received the following

error: "Connection failed:SQLSTATE[HY000][1049] Unknown database 'mydb'".

Here is the coding:

<?php
$servername = "localhost";

$username = "root";

$password = "patony";

try {
$conn = new PDO("mysql:host=localhost;dbname=myDB", "root", "patony";

//Set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE myDBPDO";

//Use exec() because no results are returned
$conn->exec($sql);
echo "Database created successfully<br>";
}
catch (PDOException $e)
{
echo $sql . "<br>" . $e->getMesssage();
}
$conn = null;
?>

I establish connection using "MySQLi Object-oriented" method and "MySQLi

procedural" method, but cannot find out the wrong with this' and would

appreciate any assistance to make it right.

Thanks

Patrick

Options: ReplyQuote


Subject
Written By
Posted
unable to open mysql database using pdp
September 09, 2016 12:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.