Encode / Decode Problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mwaw
Forum Newbie
Posts: 19
Joined: Sun Aug 11, 2002 12:31 am
Location: California

Encode / Decode Problem

Post 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
mwaw
Forum Newbie
Posts: 19
Joined: Sun Aug 11, 2002 12:31 am
Location: California

Correction

Post 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
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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".
mwaw
Forum Newbie
Posts: 19
Joined: Sun Aug 11, 2002 12:31 am
Location: California

Post by mwaw »

THANKS ROB!

That did the trick.

Mike Wilkinson
Post Reply