<?php
Error_reporting (E_all | | ~e_notice);
Header ("access-control-allow-origin:*");//This allows Web sites to be accessed across domains
Header ("Content-type:application/json;charset=utf-8");//This declaration returns a JSON type and a character set of Utf-8
$link =mysql_connect (' localhost ', ' root ', ');
if (! $link) {
echo "fail";
}
mysql_select_db ("test");
$result =mysql_query ("SELECT * from Artitle");
$json = "";
$data =array (); Defines the good one array. The array in PHP is equivalent to a data dictionary.
Define a class for storing data that is taken from the database
Class User
{
public $title;
}
while ($row = Mysql_fetch_array ($result, MYSQL_ASSOC))
{
$user =new User ();
$user->title = $row ["title"];
$data []= $user;
}
$json = Json_encode ($data);//Convert data to JSON data.
echo "{". ' " User "'.": ". $json."} ";
PHP connects to MySQL database and outputs the extracted data in JSON format