SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySQL - How to store "true/false"

    Ok.. this is kind of a dumb question, but what is the best way to store a "true or false" value with mySQL?

    Specifically, I have an "enabled" column that will only be set to "yes" or "no".

    Thanks.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    CREATE TABLE (
      flag tinyint(1) default 0 
    )
    flag = 0 (false)
    flag = 1 (true)

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer ENUM('N','Y') DEFAULT 'N', as it's more readable.
    ck :: bringing chris to the masses.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd just use a 0 or 1. If you have something like "Yes/No," or "Y/N," then you need to look for that specifically...like this:

    PHP Code:
      if ($boolean == "Y") { 
        
    // do stuff
      

    See, that way, you have to type in "Y" or "Yes" or something else like that: you need to save a tiny bit of space in your head to remember what format you're using, and you have to match it exactly. I use 0 or 1, so that I can do this:

    PHP Code:
      if ($boolean// do stuff 
    I don't have to remember if I'm using Yes/No, Y/N, or On/Off...if it's 0/1, it's a tad easier. Just my opinion. It works just as well if you're using a field that contains either a 0, or any other value, because the condition will return true so long as the value isn't 0, basically.

  5. #5
    SitePoint Zealot vodica's Avatar
    Join Date
    Jul 2001
    Location
    SLovenia
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would definetly go for a set value like 0 or 1 and then check it!
    while(true) sheep++;

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, technically, if you are looking for the minimum storage requirements then you would choose a CHAR(1) NOT NULL or a TINYINT NOT NULL which each require just one byte for storage. Otherwise, if you can spare a few bytes then it doesn't really matter.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •