PHP PDO 请求分隔关键字并且不将它们视为字符串

标签 php mysql pdo keyword keyword-search

我需要能够搜索并将不同的单词视为关键字而不是字符串。

实际上,如果我搜索“灯蓝色”,则不会显示“蓝白灯”或“蓝灯”的结果。我想将空格视为关键字分隔符。仅考虑我的实际代码,我们如何才能做到这一点?

$pdo2_where = " WHERE (" .$db_type_1_associations['nom_bot'] ." LIKE ? || " .$db_type_1_associations['id'] ." LIKE ? || " .$db_type_1_associations['nom_fr'] ." LIKE ? || " .$db_type_1_associations['description'] ." LIKE ? || " .$db_type_1_associations['commentaire_public'] ." LIKE ?)" .$pdo2_add_where_photos ;
$pdo2_execute = array (
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%',
'%' .htmlspecialchars(urldecode(trim($_GET['recherche']))) .'%'
); 

*分隔斜杠、逗号和其他经典分隔符也可能很好。

最佳答案

现在是考虑使用搜索引擎的好时机。或者如果可能的话,至少提供全文索引。

您可以仅使用 SQL 来完成此操作,但您的查询会变得更加复杂。您需要按空格分割搜索字符串,并为每个关键字和字段组合添加附加的 or 子句。

关于PHP PDO 请求分隔关键字并且不将它们视为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14327436/

相关文章:

php - PDO 以静默方式测试连接

PHP PDO 与 BindValue

sql - mysql查询和全文中的Concat()

php - 如何使用php删除未选中的值并在数据库中插入选中的值?

php - Yii2 调试 mysql 查询或 mysql_error 等效项

php echo div 类不工作

apache2 - 一次只允许一个 session

php - Laravel 5 分页

php - MySQL 统计特定记录

mysql - 聚合函数与我查询中的某些列冲突