GUID length?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    GUID length?

    Hey,

    Im doing some coding to integrate our active directory and intranet and im storing the Globally Unique Identifier (GUID) to a database.

    Does anyone know what datatype I should use for this field? I've converted it from binary to hex using bin2hex, it says its a 128bit string!?! If i know the max length would it be best just store it as text?

    Thanks for any info

    Andy
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Andy.

    Depending on how you're generating the GUID, some kind of varchar or char field would be your best bet.

    For example, if you use sha1(), all your GUIDs will be 40-character hex strings, so you could make your column a char(40) (though MySQL will automatically make it a varchar if you're using MyISAM tables).

    128 bits = 16 characters. What algorithm are you using to generate the GUID?

    Comment

    • theS70RM
      New Member
      • Jul 2007
      • 107

      #3
      Originally posted by pbmods
      Heya, Andy.

      Depending on how you're generating the GUID, some kind of varchar or char field would be your best bet.

      For example, if you use sha1(), all your GUIDs will be 40-character hex strings, so you could make your column a char(40) (though MySQL will automatically make it a varchar if you're using MyISAM tables).

      128 bits = 16 characters. What algorithm are you using to generate the GUID?

      Hi, thanks for the reply.

      Basically I get the objectguid from the Active Directory then just use bin2hex to convert the binary value to a hexadecimal one...

      would you recommend using an alternative function to do the conversion here then?

      I'm also looking to convert the hex value back so I can peform queries on the AD using the binary GUID, im not sure if this is possible yet though!

      Cheers

      Andy

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Hm. This is not my strong point; I still haven't figured out the syntax for PHP's pack() function (http://php.net/pack), which I think is what you're looking for.

        I searched around for a decent article on using pack() and unpack(). Here's one that I found: http://www.phpdig.net/ref/rn45.html.

        Comment

        • theS70RM
          New Member
          • Jul 2007
          • 107

          #5
          see my other thread for how i did this:

          http://bytes.com/forum/showthread.php? p=3338136



          Andy

          Comment

          Working...