ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:ifnull

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
reference:ifnull [2015/07/20 03:37] – [Description] mnewnhamv5:reference:connection:ifnull [2016/01/16 23:34] (current) – ↷ Page moved from v5:reference:ifnull to v5:reference:connection:ifnull mnewnham
Line 8: Line 8:
 </WRAP> </WRAP>
 ===== Description ==== ===== Description ====
-The function ''ifNull()'' returns a database-specific string providing the means to replace a null value with a specified replacement. The two parameters are:+The function ''ifNull()'' returns a database-specific string providing the means to replace a null value with a specified replacement. If the value in the database is not null, the value is not updated. The two parameters are:
  
   - The field in the table to check.   - The field in the table to check.
Line 15: Line 15:
 ===== Usage ===== ===== Usage =====
 <code php> <code php>
 +/*
 + * Assume mysql database connection
 +*/
 +$ifNullString = $db->ifNull('pants_field','chinos');
 +
 +/*
 + * ifnullString returns 'CASE WHEN pants_field is null 
 +                              THEN 'chinos' 
 +                              ELSE pants_field 
 +                              END ";
 +*/
 +
 +$SQL = "UPDATE attire 
 +           SET pants_field = $ifNullString";
 +
 +$db->Execute($SQL);
 </code> </code>
v5/reference/connection/ifnull.1437356236.txt.gz · Last modified: 2017/04/21 11:34 (external edit)