IF statement in an MySQL query

The invalid ticks are probably happening because the data isn't escaped properly. The period is usually used when a db name is specific like `dbo`.`column` so that could be why it's attempting to back tick them. If the last two values were encapsulated properly he probably wouldn't need the disable flag since it won't back tick anything in quotes.

It should be legal. Try it in raw mysql. The field is in the first parameter to the IF clause. The return values are the 2nd, or 3rd depending on if the first parameter equated to true/false. Maybe he wants a decimal returned and not a string, which is what he would get if it was surrounded by quotes.

This is valid mysql:
select if(1 = 1, .01, .05) as test;
and will return a decimal value, 0.01, as test.

I know it will work as a raw query but I still wouldn't recommend writing it like that. First I would try adding a 0 on the front to see if it ticks that correctly, if not I'd wrap them in quotes and typecast the result.

The problem with recommending disabling back ticks is someone will read that, not understand why (or which values are causing the issue) then start disabling it everywhere to avoid the problem in the future. IMO It's better to fix the query then work around it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.