全文搜索MySql PHP

全文搜索MySql PHP,php,mysql,Php,Mysql,我有一个列mysql table_php_code,其中包含列id和code_数据。我需要用代码搜索这个表,我必须得到Id e、 g id、代码和数据 1、一些php代码 2、一些php代码 现在,这个code_数据列可能包含普通php代码中的特殊字符(新行、额外空格、单引号、双引号),使用addslashes php函数存储在表中 现在,如果我有一个带有所有特殊字符的示例代码,我如何在这个表中搜索它。 简单的select语句 select * from table_php_code whe

我有一个列mysql table_php_code,其中包含列id和code_数据。我需要用代码搜索这个表,我必须得到Id

e、 g

  • id、代码和数据
  • 1、一些php代码
  • 2、一些php代码
现在,这个code_数据列可能包含普通php代码中的特殊字符(新行、额外空格、单引号、双引号),使用addslashes php函数存储在表中

现在,如果我有一个带有所有特殊字符的示例代码,我如何在这个表中搜索它。 简单的select语句

select * from table_php_code where code_data = '<code_data_to_search>';
需要搜索的示例代码

<?php

$userId=$_REQUEST["TARGET_USER_ID"];

$geolocation=$_REQUEST["TARGET_GEOLOCATION"];
$matches = preg_split("/[\s,]/", $geolocation);
$geolat=$matches[0];
$geolong=$matches[1];
$app_id="80";
$style="sban";

$max_width = $_REQUEST['max_image_width'];

if(empty($width) && (!empty($max_width)) && ($max_width > 539))  $width= '540';
if(empty($height) && (!empty($max_width)) && ($max_width > 539)) $height= '84';

if(empty($width) && (!empty($max_width)) && ($max_width > 459))  $width= '480';
if(empty($height) && (!empty($max_width)) && ($max_width > 459)) $height= '75';

if(empty($width) && (!empty($max_width)) && ($max_width > 299))  $width= '320';
if(empty($height) && (!empty($max_width)) && ($max_width > 299)) $height= '50';

if(empty($width) && (!empty($max_width)) && ($max_width > 239))  $width= '240';
if(empty($height) && (!empty($max_width)) && ($max_width > 239)) $height= '38';

if(empty($width))  $width= '320';
if(empty($height)) $height= '50';

$url="someurl".$userId."&_id=".$_id."&width=".$width."&height=".$height."&style=".$style."&lat=".$geolat."&long=".$geolong;

$info= '<script type="text/javascript" src="'.$url.'"></script>';

$info = '<meta name="viewport" content="somecontent, width=device-width, user-scalable=no" />' .$info;

echo $info;

?>

您可以使用

select * 
from table_php_code 
where MATCH (code_data) AGAINST ('some text');

如果它包含一些阻止查询的特殊字符,则必须对其进行转义:

SELECT * 
FROM table 
WHERE field LIKE 'my \"text\"' ESCAPE '\';

这将转义“\”后面的每个字符。

我不能使用全文搜索,因为表不支持它。
SELECT * 
FROM table 
WHERE field LIKE 'my \"text\"' ESCAPE '\';