MySQL Forums
Forum List  »  PHP

Syntax error preventing creating of database
Posted by: Patrick Onyilimba
Date: September 09, 2016 10:52AM

I have written a code to create a database, but I am getting, "Parse error: syntax error, unexpected ';' in C:\wamp\www\mysql\create-dbpdo.php on line 11" on running the script".

Here is a copy of the code:

<?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 have checked and rechecked to find out the problem in vain.
Your assistance is appreciated.
Thanks

Options: ReplyQuote


Subject
Written By
Posted
Syntax error preventing creating of database
September 09, 2016 10:52AM


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.