SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Column int drops the '0'

    I have a column:
    pin int DEFAULT '0' NOT NULL,

    I thought that was what I wanted, but I have a function that supplies a random number, if that number is:
    01056
    It is stored in the db as:
    1056

    This kinda screws things up a bit as I need to be able to retrieve the correct number, could some-one suggest what type of column I should use, I was thinking varchar.

    Thanks in advance

  2. #2
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right, a varchar will do it ... ie store the random number in a string format.

    Mike

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Motivated
    It is stored in the db as:
    1056
    actually, no it isn't

    integers are stored as 4-byte binary values

    1056 is stored as 0000 0100 0010 0000

    when you see 1056, you are actually seeing a decimal conversion of the real value

    if you want leading zeroes when integers are displayed, look into the ZEROFILL option
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    zerofill gives me something like:
    00000006055
    00000001056
    When all I want is :
    6055
    01056
    Using a pin as an id number with the above results would be great security, but no one would ever be able to get in, and thats not the idea.

    I'm actually quite confused and pleased some one took the time to explain the binary values.........thanks.

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should consider hasing the PIN if it's for security.

  6. #6
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    password is MD5

  7. #7
    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 need to use varchar, and you should still MD5 the pin if you can.


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
  •