Sample code One:
Set returns the JSON-formatted data
header (' Content-type:application/json;charset=utf8 ');
Connection database
$link = mysql_connect ("localhost", "root", "root") or Die ("Unable to connect to the mysql!");
mysql_query ("SET NAMES ' UTF8 '");
mysql_select_db ("Jilinwula", $link) or die ("Unable to connect to the mysql!");
Gets the paging parameter
$page = 0;
$pageSize = 3;
if (!is_null ($_get["page")) {
$page = $_get["page"];
}
if (!is_null ($_get["PageSize"])) {
$pageSize = $_get["PageSize"];
}
Query data into an array
$result = mysql_query ("Select Username,password from UserInfo limit".) $page. ", ". $pageSize. "");
$results = Array ();
while ($row = Mysql_fetch_assoc ($result)) {
$results [] = $row;
}
Converts an array to the JSON format
echo json_encode ($results);
Close connection
mysql_free_result ($result);
Mysql_close ($link);
Example code two:
<?php
//SQL statement/single
$sql = "Select Id,name from Tbl_user where id=1";
Multiple data
//$sql = "Select Id,name from Tbl_user";
Call conn.php file for database operation
require (' conn.php ');
Prompt Operation success Information, note: $result exists in conn.php file, is called out
if ($result)
{
//$array =mysql_fetch_array ($result, MySQL _ASSOC);
/* Data Set
$users =array ();
$i =0;
while ($row =mysql_fetch_array ($result, Mysql_assoc)) {
echo $row [' id ']. ' -----------'. $row [' name ']. ' </br> ';
$users [$i]= $row;
$i + +;
}
echo json_encode (Array (' dataList ' => $users));
* *
////////* $row =mysql_fetch_row ($result, MYSQL_ASSOC);
echo json_encode (Array (' Jsonobj ' => $row));
}
Mysql_free_result ($result);
Release result
mysql_close ();
Close Connection
?>
The above mentioned is the entire content of this article, I hope you can enjoy.