Why do I get a string when I retrieve a tinyint column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
etNewPHPDev
Forum Newbie
Posts: 1
Joined: Wed Oct 29, 2008 1:21 pm

Why do I get a string when I retrieve a tinyint column

Post by etNewPHPDev »

I loaded the newest version of WAMP and am doing a is_int on data I retrieved from a mySQL tinyint column and I get false. I am using mySQL 5.0. When I ask it it's type it returns string.

Any thouhgts?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Why do I get a string when I retrieve a tinyint column

Post by pickle »

All data returned in a MySQL result set is a string. You could try is_numeric() to see if it's a numeric string, or do something like this:

Code: Select all

if((int)$result['tinyIntColumn'] == $result['tinyIntColumn'])
{
  //do stuff here
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply