Cytat(php.net)
Added PDO::FETCH_KEY_PAIR mode that will fetch a 2 column result set into an associated array. (Ilia)
Niby nic trudnego. Mały test:
Kod
mysql> select id, signature from cms_items;
+----+-----------+
| id | signature |
+----+-----------+
| 1 | test |
| 2 | foo |
+----+-----------+
2 rows in set (0,00 sec)
+----+-----------+
| id | signature |
+----+-----------+
| 1 | test |
| 2 | foo |
+----+-----------+
2 rows in set (0,00 sec)
Ale jednak jakieś trudności ma mój PeHaP:
<?php $pdo = new PDO('mysql:host=localhost;dbname=work', 'wrzasq'); $stmt = $pdo->prepare('SELECT `id`, `signature` FROM `cms_items`'); $stmt->setFetchMode(PDO::FETCH_KEY_PAIR); $stmt->execute(); ?>
Nie wygląda to tak, jak oczekiwałem:
Kod
Warning: PDOStatement::setFetchMode(): SQLSTATE[22003]: Numeric value out of range: Invalid fetch mode specified in /home/wrzasq/Desktop/Www/otscms/warsztat/- on line 4
array(2) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["signature"]=>
string(4) "test"
[1]=>
string(4) "test"
}
[1]=>
array(4) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["signature"]=>
string(3) "foo"
[1]=>
string(3) "foo"
}
}
array(2) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["signature"]=>
string(4) "test"
[1]=>
string(4) "test"
}
[1]=>
array(4) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["signature"]=>
string(3) "foo"
[1]=>
string(3) "foo"
}
}
Nawet Google nie wie

BTW - Debian Sid, PHP z paczek, PDO jako moduły:
Kod
$ dpkg -l | grep php5
ii libapache2-mod-php5 5.2.3-1+b1 server-side, HTML-embedded scripting languag
ii php5-cli 5.2.3-1+b1 command-line interpreter for the php5 script
ii php5-common 5.2.3-1+b1 Common files for packages built from the php
ii php5-dev 5.2.3-1+b1 Files for PHP5 module development
ii php5-gd 5.2.3-1+b1 GD module for php5
ii php5-mysql 5.2.3-1+b1 MySQL module for php5
ii php5-pgsql 5.2.3-1+b1 PostgreSQL module for php5
ii php5-sqlite 5.2.3-1+b1 SQLite module for php5
ii php5-suhosin 0.9.20-1 advanced protection module for php5
ii libapache2-mod-php5 5.2.3-1+b1 server-side, HTML-embedded scripting languag
ii php5-cli 5.2.3-1+b1 command-line interpreter for the php5 script
ii php5-common 5.2.3-1+b1 Common files for packages built from the php
ii php5-dev 5.2.3-1+b1 Files for PHP5 module development
ii php5-gd 5.2.3-1+b1 GD module for php5
ii php5-mysql 5.2.3-1+b1 MySQL module for php5
ii php5-pgsql 5.2.3-1+b1 PostgreSQL module for php5
ii php5-sqlite 5.2.3-1+b1 SQLite module for php5
ii php5-suhosin 0.9.20-1 advanced protection module for php5
poniewaz nikt nie odpowiedzial, a na googlu wczesniej nic nie znalazlem, oprocz pytan o ten problem, to napisze sam sobie odpowiedz

ten tryb w 5.2.3 i 5.2.4 dzialal tylko jako argument dla fetchAll(). ustawic go przez setFetchMode() mozna dopiero od najnowszej wersji PHP - 5.2.5 (bug #42917).