note 125491 added to pdo.constants

From: Date: Fri, 06 Nov 2020 12:37:56 +0000
Subject: note 125491 added to pdo.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-215817@lists.php.net to get a copy of this message
PDO::FETCH_UNIQUE not only fetches the unique values, it also uses the first SQL column as array key result, what is very useful for create quickly an index, eg : <?php $sql = <<<SQL SELECT ALL c1, -- For result indexing c1, c2 FROM ( VALUES ROW('ID-1', 'Value 1'), ROW('ID-2', 'Value 2a'), ROW('ID-2', 'Value 2b'), ROW('ID-3', 'Value 3') ) AS t (c1, c2); SQL; $result = $pdo->query($sql); print_r($result->fetchAll(PDO::FETCH_UNIQUE)); /* Gives : ID-1 => [c1 => ID-1, c2 => Value 1] ID-2 => [c1 => ID-2b, c2 => Value 2b] ID-3 => [c1 => ID-3, c2 => Value 3] */ ?> ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.174 (proxied: 82.65.8.175) ---- Manual Page -- http://php.net/manual/en/pdo.constants.php Edit -- https://master.php.net/note/edit/125491 Del: integrated -- https://master.php.net/note/delete/125491/integrated Del: useless -- https://master.php.net/note/delete/125491/useless Del: bad code -- https://master.php.net/note/delete/125491/bad+code Del: spam -- https://master.php.net/note/delete/125491/spam Del: non-english -- https://master.php.net/note/delete/125491/non-english Del: in docs -- https://master.php.net/note/delete/125491/in+docs Del: other reasons-- https://master.php.net/note/delete/125491 Reject -- https://master.php.net/note/reject/125491 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215817) next »