0

Have an issue with a project in php(laravel), when i bring info from a database(mysql) and it contains accents i.e é, á . Php ends up showing a weird question mark, or crashin 'charset' => 'utf8mb4' is set in the database.php CHARACTER SET=utf8mb4 is set on every table on the mysql database

the original project had 'charset' => 'latin1' and showed problems, changing to utf8mb4 solved the problem on OSX(the test local host) but the problem didnt fix when uploaded to the server(linux)

The data comes bad before even trying to show: $example= DB::connection('mysql_db')->select("SELECT * FROM test) Log::error($example); log shows the query gets me the question mark character

Found a similar issue in: scandir issue with accents in Linux work fine in OSX But i am not sure if the answer applies only to scan dir, or to any php-linux accent issue

Community
  • 1
  • 1

2 Answers2

1

Finally made it work, had to set

'mysql' => [
    [...]
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    [...]
],

On config/database.php and set CHARACTER SET=utf8mb4; at the end of each Table in my sql file(works setting it to the whole database but another documents needed the database to be default latin1). OSX overwrites the charset of the DB with the one you set on the connection, but apparently linux doesn't allow the same. The same solution didnt work with utf8

0

I had the same issue and I manage to fix it by adding these lines in the config/database.php

'mysql' => [
    [...]
    'charset'   => 'latin1',
    'collation' => 'latin1_swedish_ci',
    [...]
],
Mathieu Ferre
  • 4,246
  • 1
  • 14
  • 31
  • thats where i set the 'charset' => 'utf8mb4', originally it was latin1 and displayed same error, when it was changed to 'charset' => 'utf8mb4' started working on OSX, but still no fix for linux – Camilo Gonzalez May 03 '17 at 14:51
  • Did you set the collation too ? If not you can check it in sequel Pro (database => modify database) – Mathieu Ferre May 03 '17 at 14:57
  • im creating the DB from scratch with an sql file so that one is not a problem, both are set charset and collation, doesnt seem to present any problem, the issue is when i change the database.php, i if set latin1, stop working on OS, nor latin1, utf seem to work on linux – Camilo Gonzalez May 03 '17 at 15:18