pq_query 由于连字符导致的语法错误。我怎么写这个?
pq_query Syntax Error because of a hyphen. How do i write this?
这行不通
$query = "SELECT * FROM time-lords WHERE user='thedoctor'";
我收到这个错误:
Warning: pg_query(): Query failed: ERROR: syntax error at or near
"-"
这个确实有效
$query = "SELECT * FROM time_lords WHERE user='thedoctor'";
所以我想问题出在连字符上。写这个的正确方法是什么?我已经尝试将列名称包装在几乎所有内容中......"time-lords"、[time-lords]、`time-lords`,但似乎没有任何效果。
您可以使用双引号转义对象名称 ("
):
$query = "SELECT * FROM \"time-lords\" WHERE user='thedoctor'";
谢谢!这解决了语法错误。为了让查询过滤,我还必须在列上使用转义双引号:
$query = "SELECT * FROM \"time-lords\" WHERE \"user\"='thedoctor'";
这行不通
$query = "SELECT * FROM time-lords WHERE user='thedoctor'";
我收到这个错误:
Warning: pg_query(): Query failed: ERROR: syntax error at or near "-"
这个确实有效
$query = "SELECT * FROM time_lords WHERE user='thedoctor'";
所以我想问题出在连字符上。写这个的正确方法是什么?我已经尝试将列名称包装在几乎所有内容中......"time-lords"、[time-lords]、`time-lords`,但似乎没有任何效果。
您可以使用双引号转义对象名称 ("
):
$query = "SELECT * FROM \"time-lords\" WHERE user='thedoctor'";
谢谢!这解决了语法错误。为了让查询过滤,我还必须在列上使用转义双引号:
$query = "SELECT * FROM \"time-lords\" WHERE \"user\"='thedoctor'";