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 revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
v5:reference:concat [2016/01/13 02:30] – ↷ Page moved from reference:concat to v5:reference:concat mnewnhamv5:reference:connection:concat [2016/01/18 02:13] – [Usage] mnewnham
Line 1: Line 1:
-====== Concat ======+====== concat ======
 ~~NOTOC~~ ~~NOTOC~~
 <WRAP right box> <WRAP right box>
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 whn 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);+
  
 /* /*
Line 21: Line 20:
 */ */
 </code> </code>
 +
 +===== Concatenating Strings And Database Fields =====
 +In order to concatenate database fields and strings together it is necessary to quote the strings
 +<code php>
 +/*
 +* 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>
 +
v5/reference/connection/concat.txt · Last modified: 2016/01/29 21:34 by mnewnham