All,
Chris makes a good point i.e., "unknown compared to anything is
unknown". His comment made me want to clarify my earlier note. In my
earlier example, I wasn't suggesting that-that logic be coded in the
database. I was assuming it would be in the page:
<?php
$TestNullValue = NULL;
If ($TestNullValue) {
print "Evaluates to true!";
} else {
print "Evaluates to false!";
}
?>
I tested this, and it worked. Here is why, PHP (like pretty much every
other language) silently casts a NULL to false:
"When converting to boolean, the following values are considered FALSE:
- the boolean FALSE itself
- the integer 0 (zero)
- the float 0.0 (zero)
- the empty string, and the string "0"
- an array with zero elements
- an object with zero member variables (PHP 4 only)
- the special type NULL (including unset variables)" ("Booleans",
php.net, 05 Dec. 2008).
If you were going to code it in the database, I'd suggest something like
this:
--Using T-SQL here...
DECLARE @TestNullValue SMALLDATETIME
SET @TestNullValue = NULL
If (@TestNullValue Is Null)
PRINT 'Evaluates to true!';
ELSE
PRINT 'Evaluates to false!';
In either case, this should have the same net result.
Be Well,
A-
-----Original Message-----
From: Chris [mailto:[EMAIL PROTECTED]
Sent: Monday, December 08, 2008 5:10 PM
To: OKi98
Cc: [email protected]
Subject: Re: [PHP-DB] MySQL Conditional Trigger
> anything compared to NULL is always false
Actually it's null.
mysql> select false = null;
+--------------+
| false = null |
+--------------+
| NULL |
+--------------+
1 row in set (0.01 sec)
mysql> select 1 = null;
+----------+
| 1 = null |
+----------+
| NULL |
+----------+
1 row in set (0.00 sec)
mysql> select 2 = null;
+----------+
| 2 = null |
+----------+
| NULL |
+----------+
1 row in set (0.00 sec)
unknown compared to anything is unknown.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php