For your problem there is pretty ready solution, that is:
$q = $db->query("SELECT `name`, `value` FROM `settings`;");
$r = $q->fetchAll(PDO::FETCH_KEY_PAIR);
Works for me, on PostgreSQL 9.1, and PHP 5.3.8 running on Windows 7 x64.
More Related Contents:
- Insert form in MySQL with PDO [duplicate]
- Undefined index $_POST
- How to check if a row exists in MySQL? (i.e. check if username or email exists in MySQL)
- Getting raw SQL query string from PDO prepared statements
- How do I set ORDER BY params using prepared PDO statement?
- “Invalid parameter number: parameter was not defined” Inserting data
- Having issue with matching rows in the database using PDO
- How can I properly use a PDO object for a parameterized SELECT query
- How do I return integer and numeric columns from MySQL as integers and numerics in PHP?
- PDO with INSERT INTO through prepared statements [closed]
- PDO::fetchAll vs. PDO::fetch in a loop
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- Real escape string and PDO [duplicate]
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- PDO Connection Test
- PHP PDO vs normal mysql_connect
- Can I create a database using PDO in PHP?
- How to bind parameters to a raw DB query in Laravel that’s used on a model?
- PHP PDO and MySQLi [duplicate]
- PDO fetch one column from table into 1-dimensional array
- Update query with PDO and MySQL
- Is “SET CHARACTER SET utf8” necessary?
- Getting a PHP PDO connection from a mysql_connect()?
- Having issue with matching rows in the database
- Set PDO to throw exceptions by default [duplicate]
- PDO: MySQL server has gone away
- Checking for an empty result (PHP, PDO, and MySQL) [duplicate]
- PHP/SQL Insert Error when using Named Placeholders
- PHP: mysql v mysqli v pdo [closed]
- PDO and MySQL ‘between’