ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:ifnull

This is an old revision of the document!


ifNull

  string ifNull(
         string $fieldToCheck,
         mixed $replacementValue
         )

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:

  1. The field in the table to check.
  2. The value to replace the null value with if it is found

Usage

/*
 * 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);
v5/reference/connection/ifnull.1448160700.txt.gz · Last modified: 2017/04/21 11:34 (external edit)