用PHP将双引号放在mysql字符串中

时间:2013-08-08 21:57:33

标签: php mysql

我在PHP中有这个代码:

$_pagi_sql='SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"$criterio"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()';

我想把这个字符串放在变量$ _pagi_sql:

SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"STH"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()

但是双引号没有正确存储在变量$ _pagi_sql

怎么做?

2 个答案:

答案 0 :(得分:0)

您可以在单引号前添加斜杠来输入双引号。

$_pagi_sql='SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST (\'"$criterio"\' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()';

答案 1 :(得分:0)

用双引号替换右手柄侧的单引号:

$_pagi_sql="SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('\"$criterio\"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()";

或者,摆脱引号,使用heredoc:

$_pagi_sql = <<<SQL
SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST ('"$criterio"' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()
SQL;