Page 1 of 1

Encode / Decode Problem

Posted: Mon Feb 24, 2003 2:57 pm
by mwaw
I'm trying to encode/decode some data, but I am apparently unable to decode it correctly.

One script uses some coding that can be simpliified like this:

mysql_query("UPDATE table SET data = ENCODE('the_data','a_password') WHERE something='something'");

Later, another script uses coding that can be simplified like this:

mysql_query("SELECT DECODE('the_data','a_password') AS data FROM table WHERE something='something'");

If I only ENCODE the data, and I don't DECODE it, my query returns a bunch of gibberish that is the same length as my original data (16 characters).

If I do DECODE the data, I get 9 characters of gibberish, but not the original 16 character data.

Any suggestions would be appreciated.

Mike Wilkinson

Correction

Posted: Mon Feb 24, 2003 2:59 pm
by mwaw
Sorry, my SELECT query should be like this:

mysql_query("SELECT DECODE('data','a_password') AS the_data FROM table WHERE something='something'");

Thanks in advance,

Mike Wilkinson

Posted: Mon Feb 24, 2003 3:19 pm
by Rob the R
Take out the quotes around data in the decode statement:

Code: Select all

mysql_query("SELECT DECODE(data,'a_password') AS the_data FROM table WHERE something='something'");
That way, it will use what's stored in the DATA column, rather than trying to decode the literal string "data".

Posted: Mon Feb 24, 2003 3:37 pm
by mwaw
THANKS ROB!

That did the trick.

Mike Wilkinson