-1

我在 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 中

怎么做到呢?

4

2 回答 2

0

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

$_pagi_sql='SELECT * FROM programas WHERE MATCH(titulo, texto,pais) AGAINST (\'"$criterio"\' IN BOOLEAN MODE) AND operador=34 And validez >= NOW()';
于 2013-08-08T21:59:54.230 回答
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;
于 2013-08-08T22:00:15.780 回答