2012-09-25 54 views
1

我有一個由我需要編輯的其他人構建的應用程序。有一個代碼區域,我找不到正確的語法......有人可以請幫忙。讓PHP讀取我的postgres select語句?

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

請幫我找了幾個小時的答案!

回答

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操作符。