Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchNum() method #101

Closed
gholol opened this issue May 18, 2015 · 6 comments
Closed

fetchNum() method #101

gholol opened this issue May 18, 2015 · 6 comments

Comments

@gholol
Copy link

gholol commented May 18, 2015

Hi

It's not really an issue, just a simple question.
I'm little surprised that there's no fetchNum() method. Do you have any plans of implementing it?

@harikt
Copy link
Member

harikt commented May 18, 2015

You mean PDO::FETCH_NUM ?

@pmjones
Copy link
Member

pmjones commented May 25, 2015

Not sure what you mean here @gholol -- can you expand a bit?

@gholol
Copy link
Author

gholol commented May 27, 2015

Well, sure guys.

Aura.Sql provides fetchAssoc() method.

We can use it like this

$result = $pdo->fetchAssoc($stm, $bind);

Now, this of course retrieves an ASSOCIATIVE array (where the key is the
first column, and the row arrays are keyed on the column names), and so, I cannot use it with list() function, because list() works only with numeric arrays.

I can do a workaround around this, and write something like:

$result = $pdo->fetchAssoc($stm, $bind);
list($value1, 
     $value2,
     $value3
) = array_keys($result);

But isn't it a bit impractical? Do you have any plans of implementing a function that returns a result as numeric array? (PDO:FETCH_NUM

@pmjones
Copy link
Member

pmjones commented May 27, 2015

This particular case ...

$result = $pdo->fetchAssoc($stm, $bind);
list($value1, 
     $value2,
     $value3
) = array_keys($result);

... might be addressed by:

$values = $pdo->fetchCol($stm, $bind);

That will populate $values with the first column of all rows in the result set. (Note that fetchAssoc() uses the first column as the array key.)

Is that sufficient, or is there another case that needs to be addressed?

@pmjones
Copy link
Member

pmjones commented May 28, 2015

@gholol Any further thoughts?

@gholol
Copy link
Author

gholol commented May 29, 2015

Hi!

Sorry for not responding, i was at work.

Your suggestion to use fetchCol() was right, it works perfectly ;) So i don't have anything else to rant about.

Have a nice day guys!

@gholol gholol closed this as completed May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants