我正在尝试创建这样的数据库:
const QUERY_DB_CREATE = "
CREATE DATABASE :db_name
";
if (database is not exists) {
$stmt = $conn->prepare(self::QUERY_DB_CREATE);
$stmt->bindValue(':db_name', $db_name, 'string');
return $stmt->execute();
}
错误
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "'testtesttest2'"
我做错了什么?
答案 0 :(得分:0)
您应该查看用于创建数据库的DoctrineBundle command(用于Symfony框架)。在不了解您的实现细节的情况下,这些行特别适用于您的情况:
$tmpConnection = DriverManager::getConnection($params);
...
$tmpConnection->getSchemaManager()->createDatabase($name);