2

I've looked through the suggested code and cannot find an answer that fixes the problem so I am asking away.

I am using MAMP v2.0.5, MySQL v5.5.9, PHP v5.3.6 (according to MAMP, v5.3.8 according to OS X) and FuelPHP v1.1, and being new to frameworks I am working through a tutorial. Part of the tutorial requires the use of 'oil' to carry out migrations to update the project. Having defined a table, the migration applies the SQL to generate the table. When I do so, I get the above error. Having looked through the generated code I can't find any errors (maybe I am missing something obvious). I am using PDO and have also checked that my sql_mode = '', which it does. Running a MySQL query from the command line and phpMyAdmin confirms this. I think this is a MySQL error and not a problem with FuelPHP/oil. Does anybody have any suggestions?

The generated SQL:

CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;

The error:

    bash:blog me$ oil refine migrate
Error - SQLSTATE[42000]: Syntax error or access violation: 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 'varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NU' at line 3 with query: "CREATE TABLE IF NOT EXISTS `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `username` varhcar(50) NOT NULL,
    `password` varchar(255) NOT NULL,
    `group` int(11) NOT NULL,
    `email` varchar(255) NOT NULL,
    `last_login` int(11) NOT NULL,
    `login_hash` varchar(255) NOT NULL,
    `profile_fields` text NOT NULL,
    `created_at` int(11) NOT NULL,
    `updated_at` int(11) NOT NULL,
    PRIMARY KEY `id` (`id`)
) DEFAULT CHARACTER SET utf8;" in COREPATH/classes/database/pdo/connection.php on line 137
Jocelyn
  • 11,209
  • 10
  • 43
  • 60
Ashley Bye
  • 1,752
  • 2
  • 23
  • 40
  • Although I have just noticed that "group" is a reserved word, having changed this to "user_group" I still get the same error. – Ashley Bye Feb 28 '12 at 00:30
  • There's also a point that doesn't need fixing as MySQL "auto-corrects" it. `PRIMARY KEY id (id)` is really the same as `PRIMARY KEY (id)`. You can't select a name for the Primary Key. It's called `PRIMARY`, by default. – ypercubeᵀᴹ Mar 25 '12 at 21:37

1 Answers1

6

You made a typo:

`username` varhcar(50) NOT NULL,

should be:

`username` varchar(50) NOT NULL,
guido
  • 18,864
  • 6
  • 70
  • 95
  • Thanks. Boy do I feel like a plonker, I've been looking at that for hours! – Ashley Bye Feb 28 '12 at 00:32
  • 1
    When mysql gives the error *.... for the right syntax to use near '__' *, just check your query in the part immediately preceding __, or the first characters in __. Error log is there to help you – guido Feb 28 '12 at 00:35
  • Thanks. I'm particularly bad when it comes to understanding the errors. Your help, albeit very easy to spot, was greatly appreciated. – Ashley Bye Feb 28 '12 at 00:38
  • There's a [campaign to clean up Stack Overflow](http://meta.stackexchange.com/q/167342) by removing these typo-related questions, we could really use your help! Would you mind pitching in a little by casting a close vote on this question? – Wesley Murch Mar 06 '13 at 21:33
  • @Wesley Murch Sure, did that. – guido Mar 06 '13 at 22:29
  • 1
    whats the difference between them ? – vaibhavatul47 Aug 21 '15 at 09:20