我将此代码编写为一个Web服务,它返回json数组可以是一个Android应用程序。
如果在运行应用程序期间MySQL数据库中有添加内容,应用程序如何解析所有数据。
<?php
ini_set('default_charset','UTF-8');
$servername = "localhost";
$username = "root";
$password = "passw";
$dbname = "db";
$conn = mysql_connect($servername, $username, $password,$dbname);
//fetch table rows from mysql db
$sql = "select * from t_name where id=1";
$result = mysql_query("SELECT ID from db.t_name where id =1" )
or die("Error in Selecting " . mysqli_error($connection));
//create an array
$emparray[] = array();
while($row =mysql_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);
//close the db connection
mysql_close($conn);
?>