mysql:将函数实现到查询中
我有一个数据库,用于存储国家、城市等地理数据。 我想使用 modrewrite 和以下链接: mysite.com/europe/austria/vienna
现在的问题是:在德语中,一些国家/地区包含变音符号,例如 austria = österreich (我不能在网址中使用变音符号)
所以我的问题: 有没有办法在数据库中创建一个函数,在查询“where validUrl(country)='oesterreich'”时替换所有特殊字符? 这将取代 ö->oe
到目前为止我唯一的想法是为 modrewrite 添加一个额外的数据库字段,这将包含“oesterreich”
任何想法?谢谢
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 field for modrewrite which would hold "oesterreich"
any ideas? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样在 MySQL 中创建一个函数,
但是正如 @GolezTrol 所说,由于其他语言中的变音符号,这不是一个好主意。
链接: http://dev.mysql.com/doc/refman /5.1/en/string-functions.html
You can create a function in MySQL like so
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
它对你没有帮助,因为虽然你可以在德语中用 ue 替换 ü ,但在其他语言中你不能用变音符号来做这样的事情。不过,您可以对这些字符进行编码,以便它们在 url 中有效。请参阅 urlencode 和 urldecode。
此外,当您将列的排序规则设置为 unicode_ci 时,您应该能够选择类似的字符串,因此
WHERE YourField = 'enquête'
也应该匹配 'enquete'。 “österreich”可能会匹配“osterreich”,但不会匹配“oesterreich”。 MySQL 可能不够聪明,无法知道这个词是法语还是德语。您可以选择特定的德语排序规则,但这不适合您的目标。阅读这篇关于排序规则的文本,因为它显示了两种德语排序规则之间的差异。
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.