$link = mysqli_connect("localhost", "root", "", "asteriskcdrdb");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$cars=array();
$query = " select * from cdr limit 5";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
echo "$row[uniqueid], $row[src]<br>";
$row[uniqueid]=array("src"=>$row[src],"dst"=>$row[dst]);
$cars[]=$row[uniqueid];
}
/* free result set */
mysqli_free_result($result);
}
$info=json_encode($cars);
print_r($info);
//else {
// printf("Error: %s\n", mysqli_error($link));
//}
/* close connection */
mysqli_close($link);
?>
[{"src":"+16145993800","dst":"s"},{"src":"+16145993800","dst":"600"},{"src":"+16145993800","dst":"600"},{"src":"100","dst":"500"},{"src":"+16145993800","dst":"600"}]
No hay comentarios:
Publicar un comentario