<?php
// set up the database as $mydb; using mysqli here, and object methods
$mydb = new mysqli('localhost','userName','password','database') ;
$mydb->query('set names utf8mb4') ;
$action = strtolower($_POST['ACTION']) ;
switch ( $action ) {
case 'getall' :
$query = "SELECT * FROM clients" ;
break ;
case 'getbyname' :
$query = sprintf("SELECT * FROM clients WHERE name = '%s'",$mydb->real_escape_string($_POST['NAME']) ;
break ;
}
$result = $mydb->query($query) ;
// check for an error, if you wish, here, then get the results:
$data = array() ;
while ( $r = $result->fetch_assoc() ) {
$data[] = $r ;
}
header('Content-Type: application/json; charset=utf-8') ;
print json_encode($data) ;
?>