Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    base 64 decode in mysql

    Hi,
    I have a table column which is base 64 encoded.

    Fields are like:
    Code:
    SQB6AHIAYQBkAGEAIABuAGEAZABzAHQAcgBlAGEBbgBpAGMAZQA=
    when i do something like this:
    Code:
    SELECT base64_decode(opis)
    FROM `gsopis` 
    WHERE `id` =1
    LIMIT 0 , 30
    Inested of:
    Code:
    Demontaza armirackog stola.
    I get:
    Code:
    D\0e\0m\0o\0n\0t\0a\0~a\0 \0a\0r\0m\0i\0r\0a\0\rk\0o\0g\0 \0s\0t\0o\0l\0a\0

    How can i get rid of unwanted characters? \0 and my language has these šđčćž, they also don't appear in string...

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You'll need to wait for the SQL guys to comment on a fix for this, but it appears to me that its simply a charset issue. The results you have are showing terminators for multibyte, so that would indicate to me that the field it has come from is a multibyte charset, while it should be stored base64 encoded within a 8bit charset like latin.
    Of course a better alternative is to simply not use base64 encoding at all and provide the field with the necessary charset to store multibyte characters.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Yeah, FouLu is right. Somehow, you managed to encode it as UTF-16 but now you are decoding it as UTF-8 (or equivalent...in any case, encoded as 16 bit, decoded as 8 bit). Maybe you changed the CHARSET in the meantime? Or maybe you encoded it with something other than MySQL?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •