1

PHP PDO's lastInsertId() method actually returns an numeric value, but it may also return something completely different like some strange SQLSTATE code or whatever. In any case it returns not a numeric value I would like to log an error. Is there a way to safely check for that?

1
  • Really?! You posted 4 questions in the last hour. Commented Dec 28, 2009 at 15:05

3 Answers 3

8

Use

is_int($value)

or

is_numeric($value)
Sign up to request clarification or add additional context in comments.

Comments

6

is_numeric returns true for numerical strings and false otherwise. A similar function is ctype_digit.

Comments

0

is_int or is_numeric is a good way.

You can also try to cast result to (int) and check if it is > 0.

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.