【问题标题】:mysql fulltext stripslashes not workingmysql全文stripslashes不起作用
【发布时间】:2015-07-06 05:06:21
【问题描述】:

我想执行这个 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 请求。

谢谢!

【问题讨论】:

  • 你能显示你得到的完整错误吗?会有很大帮助。
  • 好的,你在 php 中的“准备”是如何进行的,你也可以向 os 显示那行吗?
  • 再次感谢,再次编辑。
  • stripslashes() 派上用场的唯一可以想象的情况是当您启用了magic quotes 但它们从来都不是一个好主意并且它们在几年前被删除了。也就是说,解析错误在WHERE...因为SELECT * FROM foo WHERE bar AND WHERE gee显然是错误的SQL。

标签: php mysql pdo stripslashes


【解决方案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) ";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多