MySQL full text search Chinese solution Recently, the company project requires such a function, which is to search for Chinese in the database. It is very tricky. I searched the Internet for information and found similar articles. I record them here and hope they can help everyone. Example code: <?php /* MySQL full-text search Chinese solution! */ error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', '1'); //Database support class SaeMysql{ //phpmysql operation class} $DBS=new SaeMysql; //Add data to echo '2'; /*Create a data table*/ $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'); /*Add data*/ $title='I love you all, hello everyone'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='What is China'; $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='Question and Answer System'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title='1912.com'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); $title = '09 Network'; $DBS->runSql('INSERT INTO `ces_articles` (id,title,url) VALUES (0,\''. $title.'\',\''.str_replace('\u','u',trim(json_encode($title))).'\')'); //search: $_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 ($query as $article){ echo $article['id']; } } ?> Thank you for reading, I hope it can help you, thank you for your support of this site! You may also be interested in:
|
<<: Detailed explanation of the installation commands and usage of Docker and FastDFS
>>: Summary of Vue 3 custom directive development
This article uses an example to illustrate how to...
Change the default style of select, usually throug...
Table of contents Why do we need garbage collecti...
When the img src value is empty, two requests are ...
In Google Chrome, after successful login, Google ...
This article introduces the CSS Sticky Footer imp...
Table of contents 1. Rename table method 2. Notes...
There are two ways to disable form submission in ...
Table of contents Preface Main implementation cod...
If you don't have a Linux system, please refe...
introduce A chart is a graphical representation o...
When I used g++ to compile the cpp file for the f...
Table of contents 1. Use of arrow functions 1. Fr...
Does time really exist? Some people believe that ...
The first solution is to push the image to a publ...