Getting my head around nulls.

From: Date: Mon, 24 Sep 2001 14:58:51 +0000
Subject: Getting my head around nulls.
Groups: php.general 
Request: Send a blank email to php-general+get-68530@lists.php.net to get a copy of this message
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". Regards, Ben -- "If you criminals strong encryption ONLY the criminals will have it"

« previous php.general (#68530) next »