0

I have some code that pulls database primary keys and iterates through them by calling a function.

When I get the key from the database and do a is_int($key) it returns true.

I then call a function: thisfunction($key)

In the calling function, I made it so that you could pass in the $key and that function loads the row for that key or you can pass the row as an object. At the beginning of the called function, it checks to see if $key is_int. It is returning false when I am calling it with an integer value.

Mel
  • 3,855
  • 4
  • 24
  • 19

3 Answers3

1

Everything you get from database is string.

That means, even if you have database with INTs for columns, you are going to get them like:

id, name, age
array("43", "Rok", "19");
Rok Kralj
  • 46,826
  • 10
  • 71
  • 80
  • I am working in the Yii framework and assumed that the model would convert the string from the database to integer. I changed the check to an is_numeric() and that stopped the error. – Mel Sep 05 '11 at 16:25
  • +1 if you can proof `Everything you get from database is string.` – ajreal Sep 05 '11 at 16:25
  • @ajreal, that was with mysql&PHP in mind (I can't say that for all the databases), and also apparent that OP is using a database that converts that. – Rok Kralj Sep 05 '11 at 16:41
0

Perhaps try the ctype_digit() function.

Dachande663
  • 504
  • 1
  • 6
  • 16
0

Since everything you fetch from the database is a type string, you could try using is_numeric() instead of is_int().

mpratt
  • 1,598
  • 12
  • 21