【发布时间】:2014-03-28 17:44:46
【问题描述】:
我想实现以下,用伪mysql代码编写。
数据库表(protected_paths.tbl):
ID Path_Protected
1 /home/folder/private
2 /home/folder2/another-private
3 /home/folder3/subfolder/another/private-folder
4 /home/folder4/my_protected_folder
输入字符串:
Test | Match | String
1 | Y | /home/folder/private/another (caught by ID 1 above)
2 | Y | /home/folder/private/another/more (also caught by ID 1 above)
3 | N | /home/folder/work (not matched in table above)
4 | N | /home/folder/another-private (not matched in table above)
5 | N | /home/folder3/subfolder (not matched in table above - table above, ID 3, refers to deeper path)
显然不行:
SELECT * FROM `protected_paths` WHERE Path_Protected = '/home/folder/private/another';
SELECT * FROM `protected_paths` WHERE Path_Protected REGEXP '/home/folder/private/another';
(我希望它与 protected_paths.tbl 中的 ID 1 匹配,因为它至少包含所有字符串)
任何帮助将不胜感激。 干杯,达里尔
【问题讨论】:
标签: php mysql sql regex select