We create a test database and create a table (for example: user).
Then We add some data to it.
Now we will create two PHP pages. These are db.php (for access database) and jsondatas.php.
db.php
<?php $host="localhost"; $db="test"; $user="root"; $pass=""; $conn=@mysql_connect($host,$user,$pass) or die("Couldn't make connection."); mysql_select_db($db,$conn) or die("Couldn't select database."); mysql_set_charset('latin5',$conn); mysql_query("SET NAMES UTF8"); ?>
jsondatas.php
<?php include("db.php"); $JSON["datas"]=array(); $sql="SELECT * FROM user"; $query=mysql_query($sql); while( $row = mysql_fetch_array( $query ) ) { array_push($JSON["datas"], array('id' => $row['id'], 'name' => $row['name'], 'surname' => $row['surname'], 'mail' => $row['mail'] )); } echo json_encode($JSON); ?>
Result for jsondatas.php on execute: