Page 1 of 1

trouble with decode function

Posted: Fri Nov 15, 2002 2:25 am
by rainbow
Hi folks!

I have a trouble running encode function in MySQL. The code is something like this

Code: Select all

<?phpif(!($insert = mysql_query("INSERT INTO ct_assistant VALUES(NULL,'$student_id','$a_username', ENCODE('$ct_assistant_pwd'))",$con)))

{

                      Error(sprintf("Internal Error %d:%s\n",mysql_errno(),mysql_error()));

                      exit();

}

?>
Does anyone know what might be the problem ?

Posted: Fri Nov 15, 2002 6:25 am
by twigletmac
Are you getting an error message? Or what is happening/not happening that you don't/do expect?

Mac

Posted: Sat Nov 16, 2002 12:39 am
by MeOnTheW3
ENCODE('$ct_assistant_pwd')

Proper use: ENCODE(str,pass_str)

You are only providing one of two required values for the function. Additionally, make sure the column you wish to store the value in is defined as a blob.

Posted: Sat Nov 16, 2002 2:35 am
by rainbow
to twigletmac: Yep, i'm getting an error message.

to MeOnTheW3: ok, but should be the second value ? I mean that $pass_str ?
About the column type:yes, it's blob in the database

Posted: Sat Nov 16, 2002 8:30 am
by Rob the R
The pass_str MotW3 mentioned just represents the password that you want to associate with the encoding. You'll have to use the same password in your DECODE statment.

http://www.mysql.com/documentation/mysq ... ml#IDX1333


Now for a slight tangent, being an Oracle SQL person, the DECODE function means something different to me. In Oracle, it can be used to remap values, sort of like a simple case statement (or like an expanded IFNULL function). Is there an analog to this in MySQL?

Posted: Sat Nov 16, 2002 11:27 am
by rainbow
Thanks for help! Now it 's more or less clear.
In Oracle, it can be used to remap values, sort of like a simple case statement (or like an expanded IFNULL function). Is there an analog to this in MySQL?
Well, i don't know exactly. I'm not sure if there is that kind of function in MySQL, which is like expanded IFNULL .

Off-topic tangent follow-up

Posted: Mon Nov 18, 2002 10:44 am
by Rob the R
If I just take the time to read the docs...

I found the CASE function (statement?) in the MySQL documentation that does what the Oracle SQL DECODE function does:
http://www.mysql.com/documentation/mysq ... ml#IDX1153