Doing some DB work with PHP’s PDO. The code is very simple. Just trying to create a table in the database with prepared statement. But code is not working.
$dsn = "mysql:host=$hostname;port=$port;dbname=$database;charset=UTF8";
$pdo = new PDO($dsn, $username, $password);
$dn = 'pns';
$query_string = 'CREATE DATABASE IF NOT EXISTS :db';
$query_statement = $pdo->prepare($query_string);
if ($query_statement !== FALSE)
{
print 'Hi'; **// Code reaches here**
$statement_execute = $query_statement->execute([
':db' => $dn
]);
}
I am getting the below error instead…
Exception : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''pns'' at line 1
Please help.
Thanks.