Unable to create a database due to syntax error
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.
Subject
Written By
Posted
Unable to create a database due to syntax error
September 11, 2016 04:05AM
September 11, 2016 01:17PM
September 13, 2016 09:51AM
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.