RE: [PHP] Getting my head around nulls.

From: Date: Mon, 24 Sep 2001 15:46:55 +0000
Subject: RE: [PHP] Getting my head around nulls.
Groups: php.general 
Request: Send a blank email to php-general+get-68536@lists.php.net to get a copy of this message
> And remember "0 as a number is as important as any other number". I wish the rest of the world saw it that way! But not so... You may want to look at MySQL's IS_NULL function for retrieving data. Other than that, I don't have any good advice. It seems that if you retrieve a NULL from the database and try to assign it to a PHP variable, that variable gets destroyed. AFAIK, yes, you need a bunch of data checks, both putting data in and pulling it back out. Kirk > -----Original Message----- > From: Ben.Edwards@chase.com [mailto:Ben.Edwards@chase.com] > Sent: Monday, September 24, 2001 8:59 AM > To: php-general@lists.php.net > Subject: [PHP] Getting my head around nulls. > > > First recap (been doing RDBMS stuff for over 10 years so > reckon this is > correct). Nulls and blank are NOT the same in RDBMS (in fact > there are > actually several types of nulls). MySQL implements this > correctly (Unlike > Oracle which treats null and blank the same). Up to now I am > OK but when > it comes to codeing in PHP I am not to sure about best practice. > > The app I am working on for number datatypes inserts 0 if no data is > entered in form. I can see why, I am inserting a blank into > the database > and MySQL goes (Hang on this is a number fields and as you are not > inserting NULL you obviously mean zero). So I guess I need to do some > conditional stuff so the blanks are not actually inserted or > put null into > the PHP variable and insert this (Can PHP vars be null but > exist?). Or is > their another option? > > The second half of the issue is getting data from the > database. I added a > couple of columns to database but then I tried to retrieve them as > $row[index]. I got a variable x douse not exist error. This > really through > me until I realised it was because the value in the database > was null and > it kind of makes sense not to create the var for nulls > (although it makes > coding a pig). So again, it seems I need to do a lot of isset() stuff > which is going to be a pain. Any other insight. > > Nulls with varchar/char types are not so much of a problem as > long as you > don't mind all fields in the database being blank rather than > null after > you first insert data into them. > > It would be good to get peoples advice on this. > > And remember "0 as a number is as important as any other number".

« previous php.general (#68536) next »