如何在双引号字符串文本中转义双引号


How to escape double-quotes in a double-quoted string literal

这很奇怪,我想不通:

$query = "SELECT * FROM [master].[dbo].[TestTbl] WHERE Agentd_ID = "$_SESSION['agentid']" ";

我也试过:

 $query ='SELECT * FROM [master].[dbo].[TestTbl] WHERE Agentd_ID = "$_SESSION['agentid']" ';

我真的很感谢你们的帮助:D

您可能正在寻找

$query = "
    SELECT
        *
    FROM
        [master].[dbo].[TestTbl]
    WHERE
        Agentd_ID = '"{$_SESSION['agentid']}'"
";

但是阅读https://en.wikipedia.org/wiki/SQL_injection
然后为您的数据库(t-sql?)和/或准备好的带有参数的语句寻找合适的编码/转义函数。

另请参阅:
http://docs.php.net/manual/en/language.types.string.php
http://docs.php.net/manual/en/language.types.string.php#language.types.string.parsing