【发布时间】:2009-08-29 20:09:18
【问题描述】:
- 什么时候应该在 PHP pg 查询中使用字符 '?
- 什么时候应该在 PHP pg 查询中使用字符 "?
本题基于this answer。
【问题讨论】:
标签: php postgresql
本题基于this answer。
【问题讨论】:
标签: php postgresql
Postgres 中的字符串字面量是使用单引号定义的。双引号用于标识符周围。所以下面的查询是有效的。
SELECT "id", "name" FROM my_table WHERE "name" = 'Brian'
但是,从您链接到的答案来看,您是在询问 PHP 字符串中的单引号 ' 与双引号 ",而不是 postgres 查询。
和普通字符串一样,双引号中的字符串会插入变量,而单引号中的字符串会包含你输入的内容。
$my_var = "noob";
echo "This is a test string, $my_var\nGot it?";
>> This is a test string, noob
>> Got it?
echo 'This is a test string, $my_var\nGot it?';
>> This is a test string, $my_var\nGot it?
【讨论】:
进入 PostgreSQL 查询,必须使用 '
在 PHP 中构建查询时,可以使用 ' 或 "
"select * from table where id = 'me'"
或
'select * from table where id = \'me\''
【讨论】: