【问题标题】:PHP Postgres Driver 9.2.18 problem with simple selectPHP Postgres Driver 9.2.18 的简单选择问题
【发布时间】:2020-06-27 12:51:40
【问题描述】:

我从未在 PHP 中使用过 postgres。 现在我尝试在 Postgres 中的一个视图上进行简单的选择,但我收到了这个错误:

An error occurred: Syntax Error in SELECT * FROM 02_s3_ct13t_tariffe

似乎连接很好(如果我运行SELECT table_name FROM information_schema.tables,它可以工作,我可以在结果中看到表名02_s3_ct13t_tariffe)。

相反,如果我运行此代码,则会收到上述错误:

$conn_string = "host=xxx.xxx.xxx.xxx port=xxxx dbname=xxxx user=xxxx password=xxxxxxxx";
$db = pg_connect("$conn_string") or die('connection failed');

//$sql = "SELECT table_name FROM information_schema.tables";
$sql = "SELECT * FROM 02_s3_ct13t_tariffe";
$result = pg_query($db, $sql);

if (!$result) {
  $error = pg_last_error($db);
  echo "$error";
  exit;
}

有什么想法吗?如何检查权限或正确的语法以访问以数字开头的表名?

【问题讨论】:

  • 有人能解释一下投反对票的原因吗?

标签: php sql postgresql


【解决方案1】:

用引号将您的表格括起来(表格名称不应以数字开头):

SELECT * FROM "02_s3_ct13t_tariffe"

最好改用pdo_pqsql

【讨论】:

  • 架构名称不是必需的,但双引号是必需的!
猜你喜欢
  • 1970-01-01
  • 2013-03-17
  • 2011-10-30
  • 1970-01-01
  • 2015-01-11
  • 2023-03-24
  • 1970-01-01
  • 2011-07-01
  • 1970-01-01
相关资源
最近更新 更多