Hello,
When I use execute with some special characters (accent and such) they get corrupted. Not sure how to fix that.
Thanks,
Can confirm.
In the migration
<?php
/**
* Migrate Up.
*/
public function up()
{
$this->execute(
"UPDATE `companies` SET `deleted` = NULL, `name` = 'MyComp O脺' WHERE `companies`.`id` =1;"
);
}
In the MySQL log
122 Query START TRANSACTION
122 Query UPDATE `companies` SET `deleted` = NULL, `name` = 'MyComp O脺' WHERE `companies`.`id` =1
122 Query COMMIT
122 Query INSERT INTO phinxlog (version, start_time, end_time) VALUES ("20130328134756","2013-03-28 13:54:03","2013-03-28 13:54:03")
122 Quit
What actually ends up in the database (PMA export)
--
-- Dumping data for table `companies`
--
INSERT INTO `companies` (`id`, `name`, `address`, `notes`, `primary_contact_id`, `created`, `updated`, `deleted`) VALUES
(1, 'MyComp O脙艙', NULL, NULL, NULL, '2012-07-21 00:00:00', '2013-03-28 11:54:03', NULL);
MySQL log doesn't show anything about Phinx setting the character set. Adding
$this->execute("SET NAMES UTF8");
before the update that uses umlauts fixes the problem. I think Phinx should set the encoding to UTF8 automatically when starting migrations.
Thanks for the workaround.
hi @anroots thanks for spotting this and the workaround! I'll release it in 0.2.3.
@robmorgan Is UTF8 still forced for MySQL, or does it have to be explicitly declared in the config?
Tested on Amazon AWS / RDS, and I needed to manually set names as above.
@gwagroves You need to define the charset/collation within the configuration.
Example
environments:
default_migration_table: phinxlog
default_database: development
production:
adapter: mysql
host: localhost
name: production_db
user: root
pass: ''
port: 3306
charset: utf8
collation: utf8_unicode_ci
Most helpful comment
@gwagroves You need to define the charset/collation within the configuration.
Example
See documentation (section Configuration/Environments)