Yii Framework Forum: Null Values - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Null Values Rate Topic: -----

#1 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,695
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 01 December 2013 - 12:18 PM

As we know, NULL stands for "value is unknown (yet)".

So it can be used as a default value for foreign key, when there's no related record (actually, nulls are the only way to unset FK in most DBs except MySQL+MyISAM).

But is there such a thing as "value is known and it's empty" for STRING types?

PS. I was thinking about difference between
field_1 TEXT NULL
and
field_1 TEXT NOT NULL DEFAULT ''
and can't remember any usecase for NULL strings (except, maybe, indexing stuff).

How do you define your string fields that can be empty?
God is real unless declared as integer
0

#2 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 01 December 2013 - 01:14 PM

I do that by null or '', But there is diffrence between them:
http://stackoverflow...a/624944/926639
http://stackoverflow.../5615766/926639
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,601
  • Joined: 04-March 10
  • Location:UK

Posted 04 December 2013 - 06:20 AM

I tend to use the empty string now, rather than null. You're right that there are few uses for a null string, except maybe for differentiating between an unknown value and a value that you know is the empty string. This led Oracle to this highly debatable decision.
0

#4 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 04 December 2013 - 06:40 AM

I always use null values in the DB and PHP to mark empty fields. I never allow empty strings in user input and treat them as null values.

I can think of only one example where empty strings could be used along with null values. Null could mean the user has not entered any value and empty string could indicate that he WAS entering values but choose not to fill a specific field. But that requires the ability to save partially filled records and in most cases you just split it into two tables and use relations.

So it is confusing and I suggest using null values, not empty strings - because this is more universal considering data types other than strings (there are no "empty" integers).
Don't be a dick.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users