8

I want to use a column that contains the string encoded with base64_encode() function as primary key. But I couldn't get to learn that if same string gets different values when encoded with base64_encode().

Should I check the key existence with using encoded string in sql queries or should I get all values from DB and decode them one by one to see if that key exist? That depends on knowing if base64_encode() function always creates the same output for given string. Does it?

Thanks in advance.

kubilay
  • 5,047
  • 7
  • 48
  • 66

3 Answers3

8

Yes, the function base64_encode() always produces the same output for a given string. This is called deterministic function or deterministic algorithm.

http://en.wikipedia.org/wiki/Deterministic_algorithm

Alen Oblak
  • 3,285
  • 13
  • 27
  • "... given a particular input, will always produce the same output". thanks for the source URL. – kubilay Jan 08 '13 at 21:25
2

base64_encode is consistent and returns the same values for the same input

hatkirby
  • 850
  • 5
  • 12
2

base64 encoding always encodes data the same way, note that original encoding of string can yield in different base64 encoding.

Why on earth anyone would use a base64 encoded strings as PK beats me though

  • yeah, it beats me too. I guess I won't have a problem since I intend to use only base64_encode() and base64_decode() with no parameters etc. – kubilay Jan 08 '13 at 21:27