MySQL Forums
Forum List  »  PHP

Unable to create a database due to syntax error
Posted by: Patrick Onyilimba
Date: September 11, 2016 04:05AM

Hi

On running the following create database code, I received this error message: " Parse error:

syntax error, unexpected ';' in C:\wamp\www\mysql\create-dbpdo.php on line 11"


<!DOCTYPE html>
<html>
<body>

<?php
$servername = "localhost";
$username = "root";
$password = "patony";

try {
$conn = new PDO("mysql:host='localhost';dbname='myDBPDO'", "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;
?>

</body>
</html>

I am new in PHP and find it difficult to fix the error which I believe is here:
$conn = new PDO("mysql:host='localhost';dbname='myDBPDO'", "root", "patony";
Please help.

Options: ReplyQuote


Subject
Written By
Posted
Unable to create a database due to syntax error
September 11, 2016 04:05AM


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.