Last active
February 20, 2017 02:24
-
-
Save ardhiesta/1349b401479d38af477ee091b878e511 to your computer and use it in GitHub Desktop.
doing some SQL operation to get data from database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WorldMapper extends Mapper{ | |
// select semua data dari tabel country | |
public function getCountries(){ | |
$sql = "SELECT Name, Continent, Region from country"; | |
$stmt = $this->db->query($sql); | |
$results = []; | |
while($row = $stmt->fetch()) { | |
$results[] = array_map('utf8_encode', $row); | |
} | |
return $results; | |
} | |
// select data dari tabel country dengan pagination | |
public function getCountriesPaging($starts_record, $records_per_page){ | |
$sql = "SELECT Name, Continent, Region from country limit ".$starts_record.", ".$records_per_page; | |
$stmt = $this->db->query($sql); | |
$results = []; | |
while($row = $stmt->fetch()) { | |
// array_map('utf8_encode', $row) digunakan agar hasil query dapat terbaca | |
// ketika nanti diformat ke dalam bentuk json mengingat database world menggunakan encoding selain utf8 | |
// yang disebabkan adanya karakter-karakter unik untuk menyimpan nama negara | |
$results[] = array_map('utf8_encode', $row); | |
} | |
return $results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment