gpt4 book ai didi

php - 使用 MATCH() 搜索 mysql 数据库不起作用

转载 作者:行者123 更新时间:2023-11-29 12:58:12 26 4
gpt4 key购买 nike

stackoverflow 上有十多个关于这个主题的问题,我读了其中的大部分,但我仍然无法搜索我的数据库......!!!
这是我的表的结构:

$sql = "CREATE TABLE content.htmlLink(
LessonID INT NOT NULL,
LessonTitle VARCHAR(512) NOT NULL COLLATE utf8_general_ci,
LessonContent TEXT NOT NULL COLLATE utf8_general_ci,
storeDate VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
fileName VARCHAR(128) NOT NULL COLLATE utf8_general_ci,

FOREIGN KEY(LessonID) REFERENCES `content`.`html`(id)

);";

和父表:

$sql = "CREATE TABLE content.html(
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(512) NOT NULL COLLATE utf8_general_ci,
content TEXT NOT NULL COLLATE utf8_general_ci,
storeDate VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
tag1 VARCHAR(32) NOT NULL COLLATE utf8_general_ci,
tag2 VARCHAR(32) COLLATE utf8_general_ci,
tag3 VARCHAR(32) COLLATE utf8_general_ci,
tag4 VARCHAR(32) COLLATE utf8_general_ci,
tag5 VARCHAR(32) COLLATE utf8_general_ci,
PRIMARY KEY(id)
);";

向表中插入信息没有问题。
但是,现在我正在尝试为用户制作一个搜索引擎。我想搜索 LessonContent 中是否存在用户模式,所以我写了这行:

$sql = "SELECT * FROM content.htmllink 
WHERE MATCH(LessonTitle,LessonContent) AGAINST('$pattern')";
$query = $conn->query($sql);

//I tried to use bind param
$sql = "SELECT * FROM content.htmllink
WHERE MATCH(LessonTitle,LessonContent) AGAINST('?')";
$prepare = $conn->prepare($sql);
$prepare->execute( array( $pattern ) );
$fetch = $prepare->fetchAll();

//or with IN BOOLEAN MODE arg
$sql = "SELECT * FROM content.htmllink WHERE MATCH(LessonTitle,LessonContent) AGAINST('html', IN BOOLEAN MODE)";


即使我用特定模式检查了查询,例如:

$sql = "SELECT * FROM content.htmllink 
WHERE MATCH(LessonTitle,LessonContent) AGAINST('html')";

但是 $query 仍然是错误的。你能告诉我我的错误在哪里吗?提前致谢。我搜索了这个链接:

http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

Another site

http://dev.mysql.com/doc/refman/5.5/en/fulltext-query-expansion.html

How to search MySQL database using MATCH AGAINST method that returns only rows that have a particular field value?

How to make MYSQL search for minimum 3 keyword matches?

还有很多其他人...

最佳答案

InnoDb(Mysql Version 5.6)确实支持全文搜索。正如您提到的,您的版本低于它,因此它不支持

See the link here

关于php - 使用 MATCH() 搜索 mysql 数据库不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23718659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com