Search code examples
mysqlsyntax-errorcreate-table

Creating table mySQL syntax error


I am trying to run the following query in PHP my admin:

CREATE TABLE IF NOT EXISTS 'ibn_table' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'itransaction_id' varchar(60) NOT NULL,
'ipayerid' varchar(60) NOT NULL,
'iname' varchar(60) NOT NULL,
'iemail' varchar(60) NOT NULL,
'itransaction_date' datetime NOT NULL,
'ipaymentstatus' varchar(60) NOT NULL,
'ieverything_else' text NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

I get this error:

#1064 - 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 ''ibn_table' ( 'id' int(11) NOT NULL AUTO_INCREMENT, 'itransaction_id' varchar(' at line 1

Any help is appreciated.


Solution

  • use backtick for quoting columns and table names

    mysql> CREATE TABLE IF NOT EXISTS `ibn_table` (
        -> `id` int(11) NOT NULL AUTO_INCREMENT,
        -> `itransaction_id` varchar(60) NOT NULL,
        -> `ipayerid` varchar(60) NOT NULL,
        -> `iname` varchar(60) NOT NULL,
        -> `iemail` varchar(60) NOT NULL,
        -> `itransaction_date` datetime NOT NULL,
        -> `ipaymentstatus` varchar(60) NOT NULL,
        -> `ieverything_else` text NOT NULL,
        -> PRIMARY KEY (`id`)
        -> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    Query OK, 0 rows affected (0.12 sec)