我有两张桌子。一个存储视频信息,另一个存储与该视频关联的标签。它们共享公共字段vid_id。我试图全文搜索两个表中的匹配项。目的是,如果任一表中都有匹配项,则将从视频中收集具有该vid_id的所有字段。

问题是我的查询因Call to undefined method PDOConnectionFactory::errorInfo()而崩溃。它应该返回一行,因为标签中只有一个条目,其中名称字段= test。有人有想法么?我已经为此努力了一段时间。

CREATE TABLE IF NOT EXISTS `tags` (
  `id` varchar(35) NOT NULL,
  `vid_id` varchar(35) NOT NULL,
  `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  UNIQUE KEY `vid_id` (`vid_id`,`name`),
  FULLTEXT KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `video` (
  `timestamp` int(11) NOT NULL,
  `vid_id` varchar(32) NOT NULL,
  `file_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `uploader` varchar(55) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  `subject_id` int(1) NOT NULL,
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

$sql = "SELECT video.*
  MATCH(video.title) AGAINST('?') as cscore,
  MATCH(tags.name) AGAINST('?') as htscore
FROM video
LEFT JOIN tags ON video.vid_id=tags.vid_id
WHERE
  MATCH(video.title) AGAINST('?') OR
  MATCH(tags.name) AGAINST('?')
ORDER BY cscore DESC;";
$stmt4 = $conn->prepare($sql);
$result=$stmt4->execute(array('test','test','test','test')) or die(print_r($db->errorInfo(), true));

最佳答案

问题是您在SQL查询中的SELECT video.*后缺少逗号(,)。

工作示例:

SELECT video.*,
  MATCH(video.title) AGAINST('?') as cscore,
  MATCH(tags.name) AGAINST('?') as htscore
FROM video
LEFT JOIN tags ON video.vid_id=tags.vid_id
WHERE
  MATCH(video.title) AGAINST('?') OR
  MATCH(tags.name) AGAINST('?')
ORDER BY cscore DESC;

08-03 16:15