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.

3 Answers 3

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");
Sign up to request clarification or add additional context in comments.

3 Comments

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.
+1 if you can proof Everything you get from database is string.
@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.
0

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

Comments

0

Perhaps try the ctype_digit() function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.