pdoFetchAll() function

returns an array that consists of all the rows returned by the query, utilizing these formatting constants, such as PDO::FETCH_COLUMN, PDO::FETCH_ASSOC, ...plus other options

  • available in controllers/ - $this->model->db->pdoFetchAll()
  • available in models/   - $this->db->pdoFetchAll()
  • available in views/    - $this->_m->db->pdoFetchAll()

pdoFetchAll( $SQL, $fetchMode=PDO::FETCH_COLUMN )

  returns a plain one-dimensional array column right out of the query

    
    // Example 1   [controllers/controller] - PHP pdoFetchALL function

    $SQL = "SELECT name FROM users";
    $USERS = $this->model->db->pdoFetchAll($SQL, $fetchMode=PDO::FETCH_COLUMN );
    /** array (
      0 => 'John',
      1 => 'Mike',
      2 => 'Mary',
      3 => 'Kathy',
    ) **/
    
pdoFetchAll( $SQL, $fetchMode=PDO::FETCH_KEY_PAIR )

  returns the same column, but indexed not by numbers in order, but by another field

    
    // Example 1   [controllers/controller] - PHP fetchAll function

    $SQL = "SELECT id, name FROM users";
    $USERS = $this->model->db->pdoFetchAll($SQL, $fetchMode=PDO::FETCH_KEY_PAIR );
    /** array (
      104 => 'John',
      110 => 'Mike',
      120 => 'Mary',
      121 => 'Kathy',
    ) **/