Check if it is a valid account

0

I'm doing a MySQL query where one of the columns would be the result of a calculation.

However, I need to check by PHP if this account is valid. For example, pow (-0.2,0.5) would be an impossible value because it would be the same as trying to get the square root of a negative value. I have a problem too that in this field does not necessarily need to be an account, it might just come as the name of some table column.
I thought about using eval (), but it gives error for every time I do not insert an account but the name of a column.
Is there a way to validate if it is a possible calculation and, if it is a Any name, do nothing?

EX: select pow (-0.2,0.5), columnA, columnB from Table1 where name="John" would result in error since the first account is impossible. But it might come in the following format: select pow (columnA, columnB), columnA, columnB from Table1 where name="John" and in that case you would not have to check if it is a valid account.

    
asked by anonymous 25.04.2018 / 14:04

1 answer

0

Do you want to solve the problem by php or mysql? Also, I do not think there's what you want, you'll probably have to do a series of validations.

mysql:

select if(colA >= 0, pow(colA,ColB), 'NAN') from tabelaA where nome = 'joao';

If it is in php it is simpler because the calculation that you sent (pow (-0.2,0.5)) will not give an error, it will return you NAN. In other cases, such as taking the root of a number, just check that it is not < 0. To resolve the problem the column does not return a number you can use is_numeric or make a cast

    
25.04.2018 / 14:43