php - 让 PHP 读取我的 postgres select 语句?

标签 php postgresql sql

我有一个由其他人构建的应用程序,我需要对其进行编辑。有一个代码区域我找不到正确的语法...有人可以帮忙吗。

POSTGRES 中的 select 语句是这样的:

SELECT collection|| '/' ||color AS collection
FROM table
WHERE series = 'random number' <-- this is controlled by an array in the php 

在 php 中,现有代码如下所示:

$tableName = $db->getOne('SELECT collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{$tableName = $series['marriage_1'];}

我已经试过了,但是没用:

$tableName = $db->getOne('SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{
$tableName = $series['marriage_1'];}

请帮助我寻找这个问题的答案好几个小时了!

最佳答案

不会是这个吧?

$db->getOne('select collection || \'/\' || color as collection ...', ...);

还是这个?

$db->getOne("select collection || '/' || color as collection ...", ...);

你的尝试:

'SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?'

将结束此 SQL 到数据库:

SELECT collection, "/", color AS collection FROM item_series ...

并且 PostgreSQL 不会因为您尝试对字符串文字使用双引号而生气,它会认为您正在尝试访问名为 / 的列。此外,您想连接并为此使用 || SQL 运算符。

关于php - 让 PHP 读取我的 postgres select 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589188/

相关文章:

postgresql - 如何在使用来自同一表的不同列值条件查询时处理空值

mysql - 在 MySQL 中表示票价表

sql - ADODB RecordSet RecordCount 不返回有用信息

php - 电子邮件附件为空 PHP (Codeigniter)

php - 如何将 PHP 图片资源放入 Amazon Web Services?

sql - PostgreSQL 仅从父表中删除

具有不同记录的 SQL 增量计算

sql - 在 Hive/SQL 中获取具有最大值的行?

php - 将table1的外键设置在table2的主键的一部分上

php - 空白页用php连接HTML表单到mysql数据库