ある PHP ドキュメント ページから例をコピーして貼り付けます。ケースが似ているためです。DBH->fetch() を使用して MySQL クエリを実行すると、配列が取得されます。
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>
出力は次のようになります。
Fetch all of the remaining rows in the result set:
Array
(
[0] => Array
(
[name] => pear
[0] => pear
[colour] => green
[1] => green
)
[1] => Array
(
[name] => watermelon
[0] => watermelon
[colour] => pink
[1] => pink
)
)
「名前付き」配列要素のみを返し、数値インデックスを持つものを削除するようにドライバーに指示する方法はありますか? 何かのようなもの:
Fetch all of the remaining rows in the result set:
Array
(
[0] => Array
(
[name] => pear
[colour] => green
)
[1] => Array
(
[name] => watermelon
[colour] => pink
)
)
前もって感謝します、シモーネ