I am new to PDP PDO, this is my code to create a database named "title"
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
    $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "CREATE DATABASE title";
    // use exec() because no results are returned
    $conn->exec($sql);
    echo "Database created successfully<br>";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage(); // THIS IS LINE NUMBER 17
    }
$conn = null;
?>
But this is the error, which i get, while i try to run the script
Notice: Undefined variable: sql in C:\xampp\htdocs\website\database\createdb.php on line 17
SQLSTATE[HY000] [1049] Unknown database 'myDB'
What is wrong?
 
     
    