<?php
header("Content-type: text/json");//文本类型为json
$dbhost='localhost:33060';//主机号,一般是localhost:3306
$dbuser='root';//用户名
$dbpass='root201419';//数据库密码
//连接数据库
$conn= new mysqli($dbhost, $dbuser, $dbpass);
if(!$conn)
{
die('Could not connect:'.mysqli_error());
}
mysqli_query($conn , "set names utf8");
$sql='SELECT * FROM table59';//table是你要使用的表的名称,千万不要直接起名table,会出语法错误
mysqli_select_db($conn,'db59');//db是你要使用的数据库名称,同样也不要起名db
$result=mysqli_query($conn,$sql);
if(!$result)
{
die('无法读取数据:'.mysqli_error($conn));
}
$id=array();//在数据库中作为主键存在,以下暂时不用该变量,用户可以自行修改
$x=array();//x轴数据
$y=array();//y轴数据
$type=array();//数据类型,比如一号数据、二号数据等
$ret=array();//设置一个你将要返回的json数组
while($row=mysqli_fetch_assoc($result))
{
$x[]=$row['x'];
$y[]=$row['y'];
$type[]=$row['type'];
}
$ret = array($x,$y,$type);//注意这里面数据存储的顺序,前端会用到
echo json_encode($ret);//json编码
?>