Jump to content

[SOLVED] mysql and strings vs integers


Lodius2000

Recommended Posts

just a theory discussion here, maybe a question on the end

 

if a mysql field is set to INT, call it id,

and $id contains the integer 200

 

if i were to use this sql

 

mysql_query("SELECT field FROM table WHERE id = '$id'");

 

in the above example because of the single quotes $id is equal to a string with the value of 2next_to0next_to0 or 200, not an integer with a value of 200 above 0, right

 

so my question is, if that is true (if not tell me to shut up...heh)

 

how do I ensure that $id is an integer and not a string, because if you pass a mysql INT field a string it doesnt know how to handle it right, even if the string only contains numbers

 

thanks, happy discussing

Link to comment
https://forums.phpfreaks.com/topic/109994-solved-mysql-and-strings-vs-integers/
Share on other sites

Its nice that way so you can put pretty much anything in single quotes, makes it easier for loops and such.  Come to think of it I don't think I've had any problem putting anything into single quotes including int, string, dates etc...

 

yeah, that's the beauty of MySQL... MySQL do it for you so you do not need to worry if your int parameter is enclosed with single quote or not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.