Closed aryelgois closed 3 years ago
This is different setting. The charset for database connection is handled by database engine, and the charset encode you mentioned is handled by PHP engine. Those two things are not one-to-one, and will have different result if one of charset is not supported.
For the base framework design, this auto-encode pattern is not ideal for every situation. Somewhere may need and somewhere may not need. However, if you want this feature, you can create a wrapper of Medoo and encode the input for specific function call. All those design are just up to you.
Hey, I need to connect to an external
latin1_swedish_ci
database. So I went tonew Medoo()
and added['charset' => 'latin1']
. It probably worked, but not the way I expected.My php script is in UTF-8, so is the string I want to insert in a table. It does not contain complex characters, just Basic Latin and Latin-1 Supplement.
I was expecting Medoo to automatically re-encode the string to the defined charset, but looking in the source code, that setting is only used when connecting to the database.
It would be too complex to implement an auto encoder, because one would need to know the input encoding (we only know the 'output', to produce the query), and in some cases we would lose data.
I think it should be documented that we still need to provide data in the correct encoding.
And when fetching, I need to re-encode as well, or I just get lots of "?".
For now, I will be wrapping the data with
array_map('utf8_decode', $data)
when sending andarray_map('utf8_encode', $row)
when fetching.