<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

$conn = new mysqli("localhost", "root", "", "datos_awv16",3306);

$result = $conn->query("SELECT matricula, nombre, apellidos, sexo, semestre FROM datos");

$outp = "[";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
    if ($outp != "[") {$outp .= ",";}
    $outp .= '{"Matricula":"'  . $rs["matricula"] . '",';
    $outp .= '"Nombre":"'   . $rs["nombre"]        . '",';
    $outp .= '"Apellidos":"'   . $rs["apellidos"]        . '",';
    $outp .= '"Sexo":"'   . $rs["sexo"]        . '",';
    $outp .= '"Semestre":"'. $rs["semestre"]     . '"}'; 
}
$outp .="]";

$conn->close();

echo($outp);
?>