php - SELECT * FROM table | Only getting the first row out of all -


solved: use fetchall instead of fetch

i have simple sql query works in phpmyadmin, in php first row returned. table has lot of rows, since it's cities of world table (around 44.000 rows).

function getallcities(){         include 'db.php';          $response = json_decode('{"status":"error"}');          if(isset($_session['user'])) {             $query = $conn->prepare("select * cities_countries");             $query->execute();              $result = $query->fetch(pdo::fetch_assoc);              $response->status = "success";             $response->cities = $result;         }          echo json_encode($response);     } 

this gets returned:

{    status: "success",    cities: {       id: "1",       name: "bombuflat, india"    } } 

as mentioned above, if run query in phpmyadmin, results.

what doing wrong?

if want output results should use fetchall method

$result = $query->fetchall(pdo::fetch_assoc); 

find more details , options in manual http://www.php.net/manual/en/pdostatement.fetchall.php


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -