mySQL: Not wanted cast to integer in search query -


today found issue in 1 search query , can't find easy solution.

we have query:

select     invoice_id, firstname, lastname      table      email = '24assets@example.com' or     firstname = '24assets@example.com' or     lastname = '24assets@example.com' or     invoice_id = '24assets@example.com' 

the problem here have search invoice_id - int(10) unsigned.

mysql automatically cast 24assets@example.com integer: 24 , show results row invoice_id = 24

the solution found check number or not before send sql query , if not number execute query not containing invoice_id inside.

this example query, real query have 3 join's invoice_id

its surprised see result: 24 when execute query first time:

select invoice_id table invoice_id = '24aaa@aaa.aa' 

i didn't know cast before, because not searching stings in integer column read in google that.

i think work think handling in code (php assume?) clearer.

complex workaround:

select     invoice_id, firstname, lastname      table      email = '24assets@example.com' or     firstname = '24assets@example.com' or     lastname = '24assets@example.com' or     invoice_id = concat('','24assets@example.com' * 1) 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -