trongate / trongate-framework

The Trongate PHP framework
https://trongate.io
Other
1.11k stars 100 forks source link

Charset in db-connection #154

Closed danielldl closed 10 months ago

danielldl commented 11 months ago

Hi,

I'm pretty new to Trongate and PHP so there might be a better way to do this...

I live in Sweden and we three special characters (Å Ä Ö). When connecting to MySQL-database they are shown incorrect. I added a "charset" setting the connect string in Model.php (line 33) and it works for me. Maybe there is a better to make do it. As a setting in the config- or database (config) file?

Thanks,

Daniel

trongate commented 10 months ago

Given the fact that database connection details generally get set once and then left alone, I would recommend refraining from using problematic characters for your database credentials.

danielldl commented 10 months ago

It is not for credentials, it is for Swedish characters in the returned data. I have updated Model.php (line 33) like this and it works for me:

$this->dbh = new PDO($dsn .";charset=utf8mb4", $this->user, $this->pass, $options);