0

when I run the following:

$pdo = new PDO('sqlite:/path/to/database.db');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $pdo->prepare('CREATE TABLE IF NOT EXISTS :user (id INTEGER PRIMARY KEY AUTOINCREMENT, time INTEGER NOT NULL, ping TEXT NOT NULL);');
$user = "me";
$stmt->execute(array('user' => $user));

I get the following error, referencing the :user part of the SQL:

PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 near ":user": syntax error in /datasql.php:21\nStack trace:\n#0 /datasql.php(21): PDO->prepare('CREATE TABLE IF...')\n#1 {main}\n thrown in /datasql.php on line 21

I can't find anything wrong with the SQL and if I run the command without the variable insertion, it runs fine.

What is causing this error? Thanks ahead!

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
HelpingHand
  • 1,045
  • 11
  • 26

0 Answers0