php - mysql 全文 stripslashes 不起作用

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

谢谢!

最佳答案

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

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

关于php - mysql 全文 stripslashes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31238109/

相关文章:

php - 以HTML表格格式显示Mysql数据

php - 使用 CSS3 背景大小的封面。由于这使用了图像的 css url,是否可以在 IE8 及更早版本上全屏显示它?

php - 在 PHP 中从数组构建单个多重插入查询

php - MyISAM 或 InnoDB 用于我的大型项目,一次做多项工作

mysql - 未知变量 'default-storage-engine=myisam'

php - 我可以在 PHP 中混合使用 MySQL API 吗?

php - 使用 RoyalSlider 在两个不同的幻灯片中显示 MySQL 数据库结果

javascript - php数组没有出现在javascript中

php - Number_format PDO 结果

php - SQLSTATE[HY000] [2002] 由于目标机器主动拒绝,无法建立连接