catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Accents in WHERE clause #644

Closed theobarrague closed 6 years ago

theobarrague commented 6 years ago

I can't use "é" character in WHERE clause but I can in SELECT clause ... I've set utf-8 encoding ( without ALL requests with accents fails but WITH only WHERE fails ... )

$medoo = new Medoo\Medoo([
    'database_type' => 'mysql',
    'database_name' => '...',
    'server' => '...',
    'username' => '...',
    'password' => '...',
    'charset' => 'utf8',
    'port' => ...
]);

$medoo->update('Employé', [  
    'nom_employé' => $nom, // No error
    'prénom_employé' => $prenom, // No error
    'date_naissance_employé' => $date_naissance, // No error
    'téléphone_portable_employé' => $telephone_portable, // No error
    'id_département_employé' => $id_departement, // No error
    'id_fonction_employé' => $id_fonction // No error
], [  
    'id_employé' => $id_employe // Error : "Champ 'id_employ' inconnu dans where clause"
]);

When I try with the debbuger, i get :

UPDATE ... WHERE "id_employ" = '...' // "é" not here :/
catfan commented 6 years ago

Because Medoo only accept column name with A-Z, 0-9 and _ characters.

Andrews54757 commented 6 years ago

@catfan @Naufrage7 Replace the regex with

[\p{L}0-9_]*

It will get all letters from all languages, 0-9, and underscore.

Make sure to set /u to true

https://regex101.com/r/AAXhWz/3

However, it is not really good practice to use such characters for column names