1

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

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'];}

请帮助我已经寻找了几个小时的答案!

4

1 回答 1

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 运算符。

于 2012-09-25T19:03:43.043 回答