Syntax error preventing creating of database
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
Subject
Written By
Posted
Syntax error preventing creating of database
September 09, 2016 10:52AM
September 10, 2016 10:56PM
September 13, 2016 09:40AM
December 19, 2016 02:49AM
September 19, 2016 07:23AM
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.