note 88699 added to pdostatement.fetchall
| From: | AntP dot at osu1 dot php dot net | Date: | Wed, 04 Feb 2009 02:37:34 +0000 |
| Subject: | note 88699 added to pdostatement.fetchall | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150188@lists.php.net to get a copy of this message | ||
You might find yourself wanting to use FETCH_GROUP and FETCH_ASSOC at the same time, to get your
table's primary key as the array key:
<?php
// $stmt is some query like "SELECT rowid, username, comment"
$results = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
// It does work, but not as you might expect:
$results = array(
1234 => array(0 => array('username' => 'abc', 'comment'
=> '[...]')),
1235 => array(0 => array('username' => 'def', 'comment'
=> '[...]')),
);
// ...but you can at least strip the useless numbered array out easily:
$results = array_map('reset', $results);
?>
----
Server IP: 92.48.74.199
Probable Submitter: 87.254.95.64
----
Manual Page -- http://www.php.net/manual/en/pdostatement.fetchall.php
Edit -- https://master.php.net/note/edit/88699
Del: integrated -- https://master.php.net/note/delete/88699/integrated
Del: useless -- https://master.php.net/note/delete/88699/useless
Del: bad code -- https://master.php.net/note/delete/88699/bad+code
Del: spam -- https://master.php.net/note/delete/88699/spam
Del: non-english -- https://master.php.net/note/delete/88699/non-english
Del: in docs -- https://master.php.net/note/delete/88699/in+docs
Del: other reasons-- https://master.php.net/note/delete/88699
Reject -- https://master.php.net/note/reject/88699
Search -- https://master.php.net/manage/user-notes.php