Skip to content

Instantly share code, notes, and snippets.

@gajus
Created March 12, 2013 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gajus/5147789 to your computer and use it in GitHub Desktop.
Save gajus/5147789 to your computer and use it in GitHub Desktop.
PDO::FETCH_KEY_GROUP
PDO::FETCH_ASSOC
array(2) {
[0]=>
array(3) {
["id"]=>
int(1)
["name"]=>
string(7) "English"
["code"]=>
string(3) "eng"
}
[1]=>
array(3) {
["id"]=>
int(2)
["name"]=>
string(9) "Français"
["code"]=>
string(3) "fre"
}
}
PDO::FETCH_KEY_GROUP
array(2) {
[1]=>
array(3) {
["id"]=>
int(1)
["name"]=>
string(7) "English"
["code"]=>
string(3) "eng"
}
[2]=>
array(3) {
["id"]=>
int(2)
["name"]=>
string(9) "Français"
["code"]=>
string(3) "fre"
}
}
Implementation:
public function fetchAll ($how = null, $fetch_argument = null, $ctor_args = null) {
if ($how === PDO::FETCH_KEY_GROUP) {
$result = parent::fetchAll(PDO::FETCH_ASSOC);
return array_combine(array_map('array_shift', $result), $result);
} else {
return parent::fetchAll($how, $fetch_argument, $ctor_args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment