Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
oil refine migrate - not working as expected
  • Hi! I'm just starting with FuelPHP and it's really impressive thus far, v1.1-rc1 (from git).
    But I have one question regarding "oil refine migrate" CLI command: I have setup development environment to use MySQL db (fuel/app/config/development/db.php). I'm using default base config from fuel/app/config/development/db.php , 'type' => 'pdo' , 'charset' => 'utf8'. Although MySQL server is set with character_set_database=latin1 (Linux Mint LMDE, default mysql installation) I expected that "oil refine migrate" would create model tables with "DEFAULT CHARSET=utf8".
    But that isn't the case and every table created from scaffolding have "DEFAULT CHARSET=latin1" so all data inputed on scaffolding forms have wrong encoding. What have I missed? Is there any other place where I should have configured character set to utf8?
    Any pointers will be appreciated...
  • If DBUtil::create_table() is called without explicitly defining the charset, the charset will be loaded from the database config, like so:
    $charset = \Config::get('db.'.\Fuel::$env.'.charset', null);
    

    This means your environment must be defined correctly for it to pick up the correct charset. If your tables are created using the databases default characterset, that indicates that the configured charset could not be determined.
  • Harro Verton wrote on Tuesday 8th of November 2011:
    If DBUtil::create_table() is called without explicitly defining the charset, the charset will be loaded from the database config, like so:
    $charset = \Config::get('db.'.\Fuel::$env.'.charset', null);
    

    This means your environment must be defined correctly for it to pick up the correct charset. If your tables are created using the databases default characterset, that indicates that the configured charset could not be determined.

    Hi WanWizard! Thanks for the reply.
    ...And where do I setup this $env variable?
    I didn't find a refrence in the docs (or have I missed it)...
    Maybe You could post a link to the documentation page?
  • See http://fuelphp.com/dev-docs/general/environments.html The official docs are in sync with the current released version, which is 1.0.1, where it worked a bit differently.
  • Harro Verton wrote on Tuesday 8th of November 2011:
    See http://fuelphp.com/dev-docs/general/environments.html The official docs are in sync with the current released version, which is 1.0.1, where it worked a bit differently.

    OK. I think I got now:
    As I'm using lighttpd as web server and have not set server variable
    FUEL_ENV
    
    for virtual host I'm developing on, so the framework assumes that I'm in
    Fuel::DEVELOPMENT
    
    , which is OK, and I have set an extra key/value pair
    'charset' => 'utf8'
    
    in
    fuel/app/config/development/db.php
    
    under "default" key. So, oil now creates tables with default charset=utf8 and this is exactly what I wanted. All this is needed for me because I'm trying to rewrite using FuelPHP a rather big legacy application so I would, for the sake of simplicity, need to have old tables beside new ones (created by oil) in the same DB working in parallel until all portions of application get reworked on. Thanks again!
    :)
  • Hello folks, I'm discovering FuelPHP 1.1 RC1. I've just ran in the same trouble my tables are created in latin_swedish even if I set the charset to utf-8 in dev/config. I took my Xdebug to know why Fuel doesn't want to obey. And they're is two solutions. The first one came to me thanks to Xdebug that help me see that in core/classes/dbutils.php we are looking for a "db.development.charset" that doesn't exist, so charset is never passed to create_table. This is due to :
    $charset or $charset = \Config::get('db.'.\Fuel::$env.'.charset', null); As seen in [/b]packages/oil/classes/generate/migrations/actions.php[/b] this can be done like this :
    $charset or $charset = \Config::get('db.'.\Config::get('db.active').'.charset', null);
    And it works. The second solution is to create the database with collation AND connection collation set to 'utf8' this will create utf8 tables by default. But this doesn't fix the Fuel problem. I'll try to make a PR on dev branch. Happy coding David
  • it looks for 'db.development.charset' because the environment is set to Fuel::DEVELOPMENT, as mentioned in the above post. This section exists in the default config/development/db.php config file, this file is part of the FuelPHP distribution by default.
  • Ok but 'db.development.charset' key cannot exist as our config/development/db.php is
    return array(
     'default' => array(
      'connection'  => array(
       'dsn'        => 'mysql:host=localhost;dbname=fuel',
       'username'   => 'fuel',
       'password'   => 'fuel',
      ),
     ),
    );
    
    Keys are merged with ones in config/db.php and lives in db.default not in db.development.
    Fuel::DEVELOPMENT is only used to know witch configuration file is merged with default one. But I just see that you merged my fix to dev branch. https://github.com/fuel/core/pull/711 So thank you for your work, I continue to dive in Fuel.
    David
  • Yes, I noticed that the changes in the way the environments were setup (was all in db.php, now in separate folders) were not implemented in oil. So your fix was correct.

Howdy, Stranger!

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

In this Discussion