ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:concat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
v5:reference:connection:concat [2016/01/16 23:08]
mnewnham [Concat]
v5:reference:connection:concat [2016/01/29 21:34] (current)
mnewnham
Line 7: Line 7:
 </WRAP> </WRAP>
 ===== Description ===== ===== Description =====
-The function ''concat()'' takes an input CSV list strings, and returns a database-specific string of concatenated values+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 ===== ===== Usage =====
 <code php> <code php>
Line 13: Line 14:
  * Assume MySQL database  * Assume MySQL database
  */  */
-$list = 'VOGON,POETRY,READING';+$string $db->concat('VOGON','POETRY','READING');
  
-$string = $db->concat($list);+/* 
 + * Returns: CONCAT(VOGON,POETRY,READING) 
 + * assuming that they are database columns 
 +*/ 
 +</code>
  
 +===== Concatenating Strings And Database Fields =====
 +In order to concatenate database fields and strings together it is necessary to quote the strings
 +<code php>
 /* /*
- Returns: CONCAT(VOGON,POETRY,READING);+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"
 */ */
 </code> </code>
 +
v5/reference/connection/concat.1452982113.txt.gz · Last modified: 2017/04/21 11:36 (external edit)