Reputation: 63
I have an application that was built by someone else that I need to edit. There is an area of code that I cannot find the right syntax for ... can someone please help.
The select statement in POSTGRES goes like this:
SELECT collection|| '/' ||color AS collection
FROM table
WHERE series = 'random number' <-- this is controlled by an array in the php
in the php the existing code looks like this:
$tableName = $db->getOne('SELECT collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{$tableName = $series['marriage_1'];}
I have tried this, but it is not working:
$tableName = $db->getOne('SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?', array($series['marriage_1']));
}else{
$tableName = $series['marriage_1'];}
Please help I have looked for an answer to this for hours!
Upvotes: 1
Views: 115
Reputation: 434615
Wouldn't it be this?
$db->getOne('select collection || \'/\' || color as collection ...', ...);
Or this?
$db->getOne("select collection || '/' || color as collection ...", ...);
Your attempt:
'SELECT collection, ".'/'.", color AS collection FROM item_series WHERE series = ?'
would end this SQL to the database:
SELECT collection, "/", color AS collection FROM item_series ...
and PostgreSQL wouldn't be upset with you for trying to use double quotes for a string literal, it would think you were trying to access a column called /
. Besides, you want to concatenate and you want to use the ||
SQL operator for that.
Upvotes: 1