diff --git a/class-DBCol.php b/class-DBCol.php index 31758d0..25fb392 100644 --- a/class-DBCol.php +++ b/class-DBCol.php @@ -1,74 +1,74 @@ . /** * A database column * * This class is useful to sanitize values before inserting them into the database */ class DBCol { public $column; public $forceType; public $value; /** * @param $column string Name of the column e.g. 'user_ID' * @param $value string Related value e.g. '1' * @param $forceType string * 's' string * 'snull' string or NULL * 'd' integer * 'dnull' integer or NULL * 'f' float * 'fnull' float or NULL * '-' no sanitization at ALL */ function __construct( $column, $value, $forceType ) { $this->column = $column; $this->value = $value; $this->forceType = $forceType; } public function getType() { return $this->forceType; } public function getValue() { return $this->value; } public function setValue( $value ) { return $this->value = $value; } /** * Empty strings or zeroes can be promoted to NULL values. */ public function promoteNULL() { $type = $this->forceType; $value = $this->value; - if( 'snull' === $type && '' === $value || 'dnull' === $type && 0 === $value ) { + if( 'snull' === $type && '' === $value || 'dnull' === $type && !$value ) { $this->value = null; } } public function isString() { return $this->forceType === 's' || ( $this->forceType === 'snull' && $this->value !== null ); } }