Db storage string or int

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Db storage string or int

Post by kkonline »

In the database, i have a table storage

In the processing page i write

Code: Select all

$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

Code: Select all

VALUES('$tags',0)
INSTEAD OF

Code: Select all

VALUES('$tags','0')
Or it will be type converted automatically?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

What kind of database? Have you tried it to see what it does?
(#10850)
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

No needs to alter table.

It's automatical converted you string value into integer.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Db storage string or int

Post by califdon »

kkonline wrote:

Code: Select all

VALUES('$tags',0)
INSTEAD OF

Code: Select all

VALUES('$tags','0')
Although the database engine might convert, you should send it as the correct data type. There's no point in deliberately sending the wrong data type.
Post Reply