SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Column Choice

    ok lets say there was database that consisted of switchboard values (on or off)

    column 1 (0 or 1)
    column 2 (0 or 1)
    column 3 (0 or 1)
    column 4 (0 or 1)
    column 5 (0 or 1)
    column 6 (0 or 1)

    now all of those are what they are (they define what is activated)

    anyways right now they have their own correctponding colums, but I want to make them into one line of numbers...

    so something like this

    1010110

    pretty much like chmod only its binary...

    now which way would be best to do so. Should I make a column that is CHAR(6) or should I make a MEDIUMINT(6) colum.

    Or if its possible, can a BIT column be made, so its binary


    which way is better

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by matsko
    now which way would be best to do so
    neither of the above

    what do you want it for? how are you going to use it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well all the values that I am going to be using are bit values (on or off) and I wanted to not use about 8 columns so I thought putting them together as a bit encoded string would be a good choice. Then each time it is fetched from the database it is decoded by string charAt(). So each bit would be meant for a different switch.

    However I furthured my knowledged and formulated something even more database friendly. What I did was I converted it into binary. And then I converted the binary in Base10 (decimal 0-9) and then put that into the database as a column called config, and set it to TINYINT(3). Since its 8 bit then it easily fits for the TINTINT() (which is 8bit 0-255)

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    okay, good luck, i hope you don't have to go to a 9th bit, or do a search in the database for rows with a specific value for one of the bits (which will always require a table scan)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •