< Concatenation: Setting Operator   (Previous) Table of Contents (Next)   Delimiting Identifiers >

Concatenation: Formatting Query

/**
 * Turns the items you submit into a concatenate phrase
 *
 * @param   array|string  $in   the items you want to concatenate
 * @return  string        the query fragment your DBMS needs
 */
function formatConcatenationQuery($in) {
    $in = (array) $in;
    if ($this->ConcatenationQueryOperator == 'CONCAT()') {
        return ' CONCAT(' . implode(', ', $in) . ') ';
    } else {
        return implode(' ' . $this->ConcatenationQueryOperator . ' ', $in);
    }
}

require 'connect.inc';

$cols = array('cf', "' it.'");
$query = 'SELECT ' . $p->formatConcatenationQuery($cols) . ' FROM t';
echo "$query\n";
$out = $db->getOne($query);
echo $out;
mysql
SELECT CONCAT(cf, ' it.') FROM t
That's it.
fbsql
SELECT cf || ' it.' FROM t
That's it.