php / doc-en

English PHP documentation
484 stars 724 forks source link

PDO::FETCH_KEY_PAIR is undocumented on PDO::fetchAll #1425

Open Rolf-B opened 2 years ago

Rolf-B commented 2 years ago

Without consulting the user comments or the PDO constants list, users don't know that FETCH_KEY_PAIR exists to read a key-value list into an associative array. The PDOStatement::fetchAll page refers to PDOStatement::fetch for a list of FETCH-Values, but FETCH_KEY_PAIR makes sense only for fetchAll. So you should add something like this

To return a key-value query as an associative array, use PDO::FETCH_KEY_PAIR as query mode. The query must retrieve exacty two columns for this to work.
cmb69 commented 2 years ago

While PDO::FETCH_KEY_PAIR doesn't make much sense for PDOStatement::fetch(), it can be used with that method, so should also be listed there.