Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 12:14 PM   PM User | #1
trileletri
New to the CF scene

 
Join Date: Aug 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
trileletri is an unknown quantity at this point
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...
trileletri is offline   Reply With Quote
Old 09-22-2012, 06:39 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 09-23-2012, 11:13 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:33 PM.


Advertisement
Log in to turn off these ads.