mysql: implement function into query
i'm having a database which is storing geo-data like countries, cities. i would like to use modrewrite with links like: mysite.com/europe/austria/vienna
now the problem: in german, some countries contain umlauts like austria = österreich (i can't use umlauts in urls)
so my question: is there a way to create a function inside the database which replaces all special characters when querying like "where validUrl(country)='oesterreich' ? which would replace ö->oe
my only idea so far is adding an extra database fiel开发者_如何学Cd for modrewrite which would hold "oesterreich"
any ideas? thanks
You can create a function in MySQL like so
DELIMITER $$
CREATE FUNCTION UmlautRaus(input varchar) RETURNS varchar
BEGIN
declare output varchar;
SET output = REPLACE(input,'ü','ue');
SET output = REPLACE(output,.....
....
RETURN output;
END $$
DELIMITER ;
However as @GolezTrol said, this is not a great idea because of diacritics in other languages.
Link: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html
It won't help you, because though you can replace ü with ue in German, you can't do such things with diacritics in other languages. You can however encode these characters so they are valid in the url. See urlencode and urldecode for this.
Also, when you set the collation of the column to unicode_ci, you should be able to select similar strings, so WHERE YourField = 'enquête'
should match 'enquete' too. 'österreich' will probably match 'osterreich' but not 'oesterreich'. MySQL is probably not smart enough to know whether this word is French or German.
You could choose a specifically german collation, but this won't suit your goal. It may still be interesting to read this text on collations, since it shows the difference between two german collations.
精彩评论