Brad Hazelnut
Brad Hazelnut

Reputation: 1621

Trying to create a memory table in mysql through php

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);
  }

Upvotes: 1

Views: 1371

Answers (2)

Paul Lo
Paul Lo

Reputation: 6138

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

Upvotes: 1

L00_Cyph3r
L00_Cyph3r

Reputation: 669

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

Upvotes: 4

Related Questions