最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
mysql 全文检索中文解决方法及实例代码
时间:2017-04-26 编辑:简简单单 来源:一聚教程网
mysql 全文检索中文解决方法
最近公司项目要求这样的功能,在数据库中检索中文,很是棘手,上网查询下资料,找的类似文章,这里及记录下,希望能帮助到大家,
实例代码:
代码如下 | 复制代码 |
/* mysql全文检索中文解决方案! */ error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors','1'); //数据库支持 classSaeMysql{ //phpmysql操作类 } $DBS=newSaeMysql; //数据加入 echo'2'; /*创建数据表*/ $DBS->runSql('CREATE TABLE IF NOT EXISTS `ces_articles` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT \'\', `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `url` (`url`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC'); /*数据加入*/ $title='我爱大家啊,大家好'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='中国是什么'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='http://ask.1912news.com'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='问答系统'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='1912网'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='零九网络'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''.$title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); //搜索: $_GET['q']="中国"; echo'q'; if(isset($_GET['q'])){$sql=' match(url) against (\''.str_replace('\u','u',trim(json_encode($_GET['q']))).'\' IN BOOLEAN MODE)';} $query=$DBS->getData('SELECT * FROM `ces_articles` where '.$sql.' LIMIT 10'); echo'q'; if($query){ foreach($queryas$article){ echo$article['id']; } }
?> |
相关文章
- MySQL登录、访问及退出操作解析 10-18
- sql语句 update字段null不能用is null问题解析 09-28
- SQL Server ISNULL 不生效原因及解决分析 09-28
- 关于if exists的用法及说明分析 09-28
- Access数据库日常维护方法 09-28
- Oracle 删除大量表记录操作介绍 09-27