0

I've been creating some basic tables for my company and have come across this little problem.

When I submit this code with a normal name such as hello etc, it works fine but when I call the table "inner" or "Inner" it does not want to work.

$con = mysqli_connect($hostname, $username, $password, $db_name) or die(mysql_error()); 
if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
mysqli_query($con,"CREATE TABLE inner   ( 
                                            inner_pck_dimension             varchar                         (14),
                                            inner_pck_weight                Int                             (5),
                                            inner_pck_barcode               varchar                         (15),
                                            inner_package_paper             Int                             (5),
                                            inner_package_plastic           Int                             (5),
                                            inner_package_other             varchar                         (20)
                                        )");
    echo "Table Created";

Can anyone tell me why this is? My only assumption is that inner is a reserved word for joins.

dcaswell
  • 3,137
  • 2
  • 26
  • 25
Floyd
  • 71
  • 1
  • 7
  • 2
    couldnt you just use a different name to avoid these situations? – Carlos Oct 24 '13 at 11:55
  • 1
    it would be nice if you name it inner_tb or innertb or something like that, using reserved word will make a lot of problem even if you create the table using back tick, you'll have to keep an eye while using select, insert, update and other queries on the same table – Deepanshu Goyal Oct 24 '13 at 11:58
  • 1
    If you have this suspicion, a look at [this](http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html) tells you that you assume right. – glglgl Oct 24 '13 at 11:59
  • Thanks, I'll bookmark that page for future reference. – Floyd Oct 24 '13 at 12:40

2 Answers2

3

Inner is probably just a reserved word (see "inner join"). use backticks for names to counter this (" `inner` ")

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • 1
    by the way: you might want to avoid this alltogether. Having to use the backticks all the time gets kinda old of you're not used to it, giving you above problems (From a guy with a column-name "order" that gives off these kinds of problems :) ) – Nanne Oct 24 '13 at 11:53
  • Thank you for your answer. I intended on using a different name for the table, I just wanted to confirm my suspicions. – Floyd Oct 24 '13 at 12:37
1

Yes, I recommend against reserved words for table names, but you can usually circumvent this with "inner" if ANSI SQL Mode is enabled or 'inner' for back ticks

Answer paraphrased from this answer

Community
  • 1
  • 1
Elias
  • 2,602
  • 5
  • 28
  • 57