DboSource::boolean PHP Method

boolean() public method

Translates between PHP boolean values and Database (faked) boolean values
public boolean ( mixed $data, boolean $quote = false ) : string | boolean
$data mixed Value to be translated
$quote boolean Whether or not the field should be cast to a string.
return string | boolean Converted boolean value
    public function boolean($data, $quote = false)
    {
        if ($quote) {
            return !empty($data) ? '1' : '0';
        }
        return !empty($data);
    }

Usage Example

 /**
  * Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans
  *
  * @access public
  * @return void
  */
 function testBooleanNormalization()
 {
     $this->assertTrue($this->db2->boolean('t'));
     $this->assertTrue($this->db2->boolean('true'));
     $this->assertTrue($this->db2->boolean('TRUE'));
     $this->assertTrue($this->db2->boolean(true));
     $this->assertTrue($this->db2->boolean(1));
     $this->assertTrue($this->db2->boolean(" "));
     $this->assertFalse($this->db2->boolean('f'));
     $this->assertFalse($this->db2->boolean('false'));
     $this->assertFalse($this->db2->boolean('FALSE'));
     $this->assertFalse($this->db2->boolean(false));
     $this->assertFalse($this->db2->boolean(0));
     $this->assertFalse($this->db2->boolean(''));
 }
All Usage Examples Of DboSource::boolean
DboSource