SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)

    BOOLEAN - putting in and taking out true/false instead of 1/0

    In mysql 5.0, as far as I understand it, BOOLEAN is an alias for tinyint(1)

    How far does that aliasing go?

    When you INSERT, does it have to be a 1 or 0, or can it be a true/false?

    Same with SELECT, does it have to return 1/0, or can it be true/false?


    If it matters, I'm working with PHP.

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://dev.mysql.com/doc/refman/5.0/...-overview.html

    BOOL, BOOLEAN

    These types are synonyms for TINYINT(1). A value of zero is considered false. Non-zero values are considered true...
    However, the values TRUE and FALSE are merely aliases for 1 and 0, respectively...

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Read it already...didn't quite answer my question.

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you can do this:
    Code:
    insert foo (bar) values (true), (false)
    but SELECT will always return 1 or 0. in php's case, that fine because an integer value of 0 is false.

    and when the manual says that something is an alias of something else, it's very literal. there is no special or added functionality just because its an alias.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    ah-ha...so that's why it's never been changed to a real boolean datatype, unlike with PostgreSQL. Makes a *lot* more sense now.

    Thanks


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
  •