mysql全文striplashes不工作

时间:2015-07-06 05:06:21

标签: php mysql pdo stripslashes

我想执行这个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类使用预处理语句,我有这段代码:

 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请求。

谢谢!

1 个答案:

答案 0 :(得分:1)

哦,我花了一些时间才找到错误,但这确实是错误的:

$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) ";