ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:concat

concat

string concat(
       string $inputString
       )

Description

The function concat() takes an variable list of strings, and returns a database-specific string of concatenated values. It is important to recognize the difference between concatenating a database field or a string when using the method in an SQL statement


Usage

/*
 * Assume MySQL database
 */
$string = $db->concat('VOGON','POETRY','READING');
 
/*
 * Returns: CONCAT(VOGON,POETRY,READING)
 * assuming that they are database columns
*/

Concatenating Strings And Database Fields

In order to concatenate database fields and strings together it is necessary to quote the strings

/*
* Best methodology
*/
$s = $db->quote(', Arthur Dent');
 
$SQL = "UPDATE hitchhikers 
           SET last_name = {$db->concat(last_name,$s)} 
         WHERE first_name='Arthur' 
           AND last_name='Dent'";
 
$db->execute($SQL);
 
$SQL = "SELECT last_name FROM hitchhikers 
         WHERE first_name='Arthur'";
 
print $db->getOne($SQL);
 
/*
* Prints "Dent, Arthur Dent"
*/
v5/reference/connection/concat.txt · Last modified: 2016/01/29 21:34 by mnewnham