trouble with decode function

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
rainbow
Forum Newbie
Posts: 13
Joined: Thu Aug 22, 2002 6:03 am
Location: Finland

trouble with decode function

Post 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 ?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Are you getting an error message? Or what is happening/not happening that you don't/do expect?

Mac
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post 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.
rainbow
Forum Newbie
Posts: 13
Joined: Thu Aug 22, 2002 6:03 am
Location: Finland

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

Post 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?
rainbow
Forum Newbie
Posts: 13
Joined: Thu Aug 22, 2002 6:03 am
Location: Finland

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

Off-topic tangent follow-up

Post 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
Post Reply