Skip to content

Instantly share code, notes, and snippets.

@pratamawijaya
Created October 15, 2013 08:54
Show Gist options
  • Save pratamawijaya/6988689 to your computer and use it in GitHub Desktop.
Save pratamawijaya/6988689 to your computer and use it in GitHub Desktop.
webservice file
<?php
class Database {
private $host = "localhost";
private $user = "root";
private $pass = "root";
private $db = "wisata_jogja";
private $conn;
// constructor
function __construct() {
try{
$this->conn = new PDO( "mysql:host=".$this->host.";dbname=".$this->db, $this->user, $this->pass );
}catch( PDOException $e ) {
echo "error pdo $e";
}
}
public function showAllData( $table ) {
$sql ="SELECT * FROM $table";
$q = $this->conn->query( $sql ) or die( "Failed !!" );
while ( $r = $q->fetch( PDO::FETCH_ASSOC ) ) {
$data[] = $r;
}
return $data;
}
}
$database = new Database();
$response = array();
if ( isset( $_GET['get'] ) && $_GET['get']=='lokasi' ) {
$response['location'] = array();
foreach ( $database->showAllData( 'lokasi' ) as $value ) {
$kode = array();
extract( $value );
$kode['id'] = $id;
$kode['nama'] = $nama;
$kode['alamat'] = $alamat;
$kode['lat'] = $lat;
$kode['lng'] = $lng;
$kode['gambar'] = $gambar;
array_push( $response['location'], $kode );
}
echo json_encode( $response );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment