0

This is driving me crazy. For some weird reason, pdo's fetch style parameter's datatype is integer? It can't be integer, its more like a string without quotes around it.. Plus there is no numbers in it. I found it, when i was trying to make pdo function library, but it's not so important to this. Check this out:

echo gettype(PDO::FETCH_ASSOC); // returns 'integer'

What is this all about??

4
  • I think you have an error in your query and you get false or 0. Can you show us your query before? Commented Dec 30, 2013 at 14:02
  • No, the question is not about queries, its about fetch styles datatype. Commented Dec 30, 2013 at 14:03
  • The documentation states it's an integer (php.net/manual/en/pdo.constants.php), PDO::FETCH_ASSOC is a flag. See 3v4l.org/i6SFv for PDO constants and their values. Commented Dec 30, 2013 at 14:10
  • Why downwote please explain that unfriendly behaviour. Commented Dec 30, 2013 at 14:15

2 Answers 2

2

As per the PHP docs the fetch_style parameter is of type int, As per PHP docs

  fetch_style Controls how the next row will be returned to the caller. This value must be
 one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE 
(which defaults to PDO::FETCH_BOTH)

where PDO::FETCH_ASSOC is a constant whose value is 2. And the gettype function returns the type of variable.

Sign up to request clarification or add additional context in comments.

Comments

1

So you have edit your Question this is not a problem. PDO::FETCH_ASSOC is a constant in the PDO Class.

http://www.php.net/manual/en/pdo.constants.php

Here you can see all constants and you can see that the PDO:FETCH_ASSOC is an integer. This is only that you can use a defined value.

4 Comments

Yes but how this can be integer? Should it be something like flag or function parameter by its datatype?
@aksu Do you know what constants are? What's wrong with it being an integer?
@asku i don't see the problem look into the PDO Class there you can see all the constants that are defined in the class on top. You could write the integer value in the function but in most cases you don't know that 2 is for fetch assoc for example
Okayy!! So the pdo converts it to integer to match fetch style! clever!

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.