0

I'm trying to create a table with mysqli->prepare, but get an error while preparing the statement. My statement is as follows:

$mysqli->prepare("CREATE TABLE ? (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY (id))");

Then I just bind the table name to it

$mysqli->bind_param("s", $some_name);

And execute it.

$mysqli->execute();

The error I get is:

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 '? (id INT AUTO_INCREMENT NOT NULL, PRIMARY KE' at line 1

Can you help me?

lukas293
  • 518
  • 1
  • 3
  • 15

2 Answers2

2

See http://php.net/manual/en/mysqli-stmt.prepare.php

In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements.

nlu
  • 1,903
  • 14
  • 18
0

This seems to have been answered before. Can I parameterize the table name in a prepared statement? You can't bind the table name

Community
  • 1
  • 1
Zoltar
  • 232
  • 1
  • 4
  • 10