1

I am trying to create a memory table in mysql through php but i keep getting an error:

Error creating database: 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 'Order INT)ENGINE = INNODB' at line 1 

Below is the code that i am using to try and create it:

$sql = "CREATE TABLE Persons(FirstName CHAR(30),LastName CHAR(30),Age INT, Order INT)ENGINE = MEMORY";
if (mysqli_query($con,$sql))
  {
  echo "Database my_db created successfully";
  }
else
  {
  echo "Error creating database: " . mysqli_error($con);
  }
Brad Hazelnut
  • 1,603
  • 5
  • 21
  • 33

2 Answers2

4

Make sure you are escaping the predefined constants in MySQL like 'order'

$sql = "CREATE TABLE `Persons`(`FirstName` CHAR(30),`LastName` CHAR(30),`Age` INT, `Order` INT)ENGINE = MEMORY";

See this post for more clarification:

Using backticks around field names

Community
  • 1
  • 1
L00_Cyph3r
  • 669
  • 4
  • 18
1

Order is a reserved word in sql, try replace it with other terminology.

Paul Lo
  • 6,032
  • 6
  • 31
  • 36