Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
generated oil resulting to a mysql syntax error
  • I was following this tutorial on implementing a login system with FuelPHP. started with:
    php oil generate scaffold user username:string password:string email:string profile_fields:text group:integer[11] last_login:integer[20] login_hash:string
    
    but when i
    php oil r migrate
    
    it suddenly outputs an error:
    Error - SQLSTATE[42000]: Syntax error or access violation: 1064 You have an erro
    r in your SQL syntax; check the manual that corresponds to your MySQL server ver
    sion for the right syntax to use near 'group int(11) NOT NULL,
            last_login int(20) NOT NULL,
            login_hash varchar(255) N' at line 7 with query: "CREATE TABLE IF NOT EX
    ISTS users (
            id int(11) NOT NULL AUTO_INCREMENT,
            username varchar(255) NOT NULL,
            password varchar(255) NOT NULL,
            email varchar(255) NOT NULL,
            profile_fields text NOT NULL,
            group int(11) NOT NULL,
            last_login int(20) NOT NULL,
            login_hash varchar(255) 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 o
    n line 137
    

    I've inspected my migration file and i don't see anything wrong:
    namespace Fuel\Migrations;
    
    class Create_users {
    
     public function up()
     {
      \DBUtil::create_table('users', array(
       'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
       'username' => array('constraint' => 255, 'type' => 'varchar'),
       'password' => array('constraint' => 255, 'type' => 'varchar'),
       'email' => array('constraint' => 255, 'type' => 'varchar'),
       'profile_fields' => array('type' => 'text'),
       'group' => array('constraint' => 11, 'type' => 'int'),
       'last_login' => array('constraint' => 20, 'type' => 'int'),
       'login_hash' => array('constraint' => 255, 'type' => 'varchar'),
       'created_at' => array('constraint' => 11, 'type' => 'int'),
       'updated_at' => array('constraint' => 11, 'type' => 'int'),
      ), array('id'));
     }
    
     public function down()
     {
      \DBUtil::drop_table('users');
     }
    }
    

    EDIT: It turned out it worked on mysql on localhost but not on PDO :|
  • I have a feeling this has nothing to do with the fact that you use a PDO connection, but with the fact that at the end of that connection is a MySQL v5 server in STRICT MODE. In that mode, you can not create a table with a column 'not null' that does not have a default value.
  • @WanWizard, Thank you! I'll just stick with mysqli.
  • The connection method is not the issue here. The problem is that the SQL generated by your create_table() code is not acceptable to your MySQL service because it is running in strict mode. You will even get the error if you would try to execute the same SQL using PHPMyAdmin of the mysql commandline tools...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion