[SQLite] Utilisation de REGEXP
Bonjour,
Je suis surpris de ne pas avoir trouvé la réponse à ma question, ni dans le forum, ni sur php.net .
J'espère ne pas avoir mal cherché...
J'interroge une bdd SQL avec sqlite_query()
Je souhaite passer une requête :
Code:
1 2
|
SELECT * FROM datas WHERE champ REGEXP "essai"; |
Ce qui échoue.
Apparemment REGEXP dans SQLite ne marche pas par défaut :
Citation:
The REGEXP operator is a special syntax for the regexp() user function. No regexp() user function is defined by default and so use of the REGEXP operator will normally result in an error message. If a user-defined function named "regexp" is added at run-time, that function will be called in order to implement the REGEXP operator.
J'ai essayé de définir ainsi la fonction :
Code:
1 2 3 4 5 6 7 8 9 10
|
function sqlite_regex($str, $regex) {
if (preg_match($regex, $str, $matches)) {
return $matches[0];
}
return false;
}
sqlite_create_function($this->db, 'REGEXP', 'sqlite_regex', 2);
$result = sqlite_array_query($this->db, 'SELECT * FROM datas WHERE champ REGEXP "tex"' , SQLITE_ASSOC); |
Mais sans succès :
Citation:
Warning: sqlite_array_query() [function.sqlite-array-query]: near "REGEXP": syntax error
Quelqu'un a une idée ?
Merci.