Forum Moderators: open

Message Too Old, No Replies

Db storage string or int

         

kkonline

4:36 am on Aug 25, 2007 (gmt 0)

10+ Year Member



In the database, i have a table storage

In the processing page i write


$sql="INSERT INTO storage (tags,trusted)VALUES('$tags','0')";

The table storage has tags as text and trusted as tinyint(1);

The above query send trusted values as a string(i think) but in db it's of tinyint(1)

So is there any need to send values as

VALUES('$tags',0)

INSTEAD OF

VALUES('$tags','0')

Or it will be type converted automatically?

dmorison

9:10 pm on Aug 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't say what language / DB you are using, but it looks like PHP, and assuming that you are talking about MySQL; then the answer is that it makes no difference.

'0'

and

0

are identical within a query.

However,

It is BEST PRACTICE to ALWAYS delimit field values between ', and further still, make sure that the values are safe to insert into a query, for example by using mysql_escape_string()...