mysql 全文 stripslashes 不工作

mysql fulltext stripslashes not working

我想执行此 mysql 搜索:

 SELECT ida, MotsClef FROM Actes WHERE MATCH (MotsClef ) 
 AGAINST ('+"dette" +"plège"' IN BOOLEAN MODE);

使用 php,我使用正则表达式将 +" 和 " 添加到通过 $_POST 接收的表达式中,因此 var_dump 给出:

'motcle' => string '+"dette" +"plège"'

那也很好。但是,我使用 PDO class 使用准备好的语句,并且我有这段代码:

 if($r['motcle']!=''){
     $motclef = $r['motcle'];
     $demMotsClef = " AND WHERE MATCH (MotsClef ) AGAINST (:motsclef IN BOOLEAN MODE) ";
    }
    else{
            $demMotsClef='';
    }

比:

 $f = "SELECT COUNT(*) FROM Actes, Bibliographie WHERE id = idBiblio".$demMotsClef;

$demande = $this->prepare($f);

if($r['motcle']!=''){$demande->bindValue(':motsclef',stripslashes($motclef));}

$demande->execute(); //the error is on this line//

我收到一条 MySQL 错误消息,说我的 SQL 语法有误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the 
right syntax to use near 'WHERE MATCH (MotsClef ) AGAINST 
('+\"dette\" +\"plège\"' IN BOOLEAN MODE) AND a' at line 1' in 
/Library/WebServer/Documents/messources/actions.class.php on line 547.

mysql 语法中的错误是添加了斜杠,因此使用了 stripslashes(不起作用)。

关于如何解决这个问题的任何想法 - 我宁愿不在 php.ini 或 .php 函数中更改 ini 设置,因为那样会弄乱我的所有其他 mysql请求。

谢谢!

哦,我花了一段时间才找到错误,但这绝对是错误的:

$demMotsClef = " AND WHERE MATCH (MotsClef ) AGAINST (:motsclef IN BOOLEAN MODE) ";

$f = "SELECT COUNT(*) FROM Actes, Bibliographie WHERE id = idBiblio".$demMotsClef;

如果你看这个,你会有两个 WHERE,这是不允许的,你应该做出这样的改变:

$demMotsClef = " AND MATCH (MotsClef ) AGAINST (:motsclef IN BOOLEAN MODE) ";