要求是获取用户提供的关键字列表,并返回在 16 个字段中的任何一个字段中包含任何关键字的任何记录。
所以如果用户输入cup dog bread
的关键词(关键词的顺序不重要,没有任何隐含关系。)
所以 WHERE 条件的数量是 78:
WHERE ObjObjectName LIKE '%cup%'
OR ObjObjectName LIKE '%dog%'
OR ObjObjectName LIKE '%bread%'
OR ObjObjectOtherName LIKE '%cup%'
OR ObjObjectOtherName LIKE '%dog%'
OR ObjObjectOtherName LIKE '%bread%'
OR ObjObjectID LIKE '%cup%'
OR ObjObjectID LIKE '%dog%'
OR ObjObjectID LIKE '%bread%'
OR ObjOtherName LIKE '%cup%'
OR ObjOtherName LIKE '%dog%'
OR ObjOtherName LIKE '%bread%'
OR ObjTitle LIKE '%cup%'
OR ObjTitle LIKE '%dog%'
OR ObjTitle LIKE '%bread%'
OR ObjCategory LIKE '%cup%'
OR ObjCategory LIKE '%dog%'
OR ObjCategory LIKE '%bread%'
OR AccCreditLineLocal LIKE '%cup%'
OR AccCreditLineLocal LIKE '%dog%'
OR AccCreditLineLocal LIKE '%bread%'
OR PrimaryCreator LIKE '%cup%'
OR PrimaryCreator LIKE '%dog%'
OR PrimaryCreator LIKE '%bread%'
OR EdiPublisherLocalSummary LIKE '%cup%'
OR EdiPublisherLocalSummary LIKE '%dog%'
OR EdiPublisherLocalSummary LIKE '%bread%'
OR EdiPlaceOfPublication LIKE '%cup%'
OR EdiPlaceOfPublication LIKE '%dog%'
OR EdiPlaceOfPublication LIKE '%bread%'
OR CreContinent LIKE '%cup%'
OR CreContinent LIKE '%dog%'
OR CreContinent LIKE '%bread%'
OR CreSubContinent LIKE '%cup%'
OR CreSubContinent LIKE '%dog%'
OR CreSubContinent LIKE '%bread%'
OR CreCountry LIKE '%cup%'
OR CreCountry LIKE '%dog%'
OR CreCountry LIKE '%bread%'
OR CreRegion LIKE '%cup%'
OR CreRegion LIKE '%dog%'
OR CreRegion LIKE '%bread%'
OR CreCounty LIKE '%cup%'
OR CreCounty LIKE '%dog%'
OR CreCounty LIKE '%bread%'
OR CreStateProvince LIKE '%cup%'
OR CreStateProvince LIKE '%dog%'
OR CreStateProvince LIKE '%bread%'
OR CreCity LIKE '%cup%'
OR CreCity LIKE '%dog%'
OR CreCity LIKE '%bread%'
OR CreContinent1 LIKE '%cup%'
OR CreContinent1 LIKE '%dog%'
OR CreContinent1 LIKE '%bread%'
OR CreSubContinent1 LIKE '%cup%'
OR CreSubContinent1 LIKE '%dog%'
OR CreSubContinent1 LIKE '%bread%'
OR CreCountry1 LIKE '%cup%'
OR CreCountry1 LIKE '%dog%'
OR CreCountry1 LIKE '%bread%'
OR CreRegion1 LIKE '%cup%'
OR CreRegion1 LIKE '%dog%'
OR CreRegion1 LIKE '%bread%'
OR CreCounty1 LIKE '%cup%'
OR CreCounty1 LIKE '%dog%'
OR CreCounty1 LIKE '%bread%'
OR CreStateProvince1 LIKE '%cup%'
OR CreStateProvince1 LIKE '%dog%'
OR CreStateProvince1 LIKE '%bread%'
OR CreCity1 LIKE '%cup%'
OR CreCity1 LIKE '%dog%'
OR CreCity1 LIKE '%bread%'
OR CreDateCreated LIKE '%cup%'
OR CreDateCreated LIKE '%dog%'
OR CreDateCreated LIKE '%bread%'
OR CreMarkSignature LIKE '%cup%'
OR CreMarkSignature LIKE '%dog%'
OR CreMarkSignature LIKE '%bread%'
这真的是最好的方法吗?我的意思是,我打算使用 PDO 准备语句,我发现这个问答(使用 PDO 准备语句的搜索字段中的多个关键字进行 LIKE 查询)这将非常有帮助,但我对 MySQL 相对缺乏经验,所以我不确定是否有是处理所有条件的更好方法。谢谢!