<?php
/**
* 数据库配置信息
*/
$db_config = array(
'host' => "localhost",
'user' => "root",
'password' => "root",
'database' => "map"
);
/**
* flush outputbuffer并将其输出到客户端,可实现即时输出
* @param unknown_type $str
*/
function qk_echo($str) {
echo $str;
ob_flush();//刷新缓存
flush();
}
/**
* Helper 类,用于接收http请求并对外提供服务
*/
class Helper{
private $db_config;
public function __construct($db_config){
$this->db_config=$db_config;
}
/**
* 对外提供api接口
* @param method api名称
*/
public function do_api(){
$method=$_GET['method'];
$result="";
switch ($method) {
case 'get_trj':
# code...
$result=$this->get_trj();
break;
default:
# code...
break;
}
qk_echo($result); //Response
}
/**
* 获取轨迹信息,以字符串的形式返回
*/
public function get_trj(){
//初始化数据库连接
$conn=mysqli_connect($this->db_config['host'], $this->db_config['user'],$this->db_config['password']);
//选择数据库
@mysqli_select_db($conn,$this->db_config['database']);
//$table_name="trajectory";
//$table_name="ap_max";
$table_name="wifi_state";
//$sql="select id,lng,lat,ssid,rssiMax,rssiMin,wifi_mac,testPointNum,wifi_mac_used from ".$table_name;
//$sql="select id,lon,lat,time,encyptiontype,rssi,name from ".$table_name;
$sql="select id,lon,lat,time,encyptiontype,rssi,name from wifi_state";
// 执行sql查询
$rs=mysqli_query($conn,$sql);
if (!$rs) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$result=array();
while($row=mysqli_fetch_row($rs)){
//加入经纬度信息
//echo $row[1];
$result[]=array($row[1],$row[2],$row[3],$row[4],$row[5],$row[6]);
//$result[]=array($row[1],$row[2],$row[3],$row[4]);
}
//关闭数据集
@mysqli_close($rs);
//返回结果
return json_encode($result);
}
}
/*
//测试连接数据库用,debug时,连接成功后,注释掉
$link=mysqli_connect("localhost","root","root");
if(!$link) echo "连接错误,数据库host或用户名或密码不对";
else echo "连接成功";
*/
$helper=new Helper($db_config);
$helper->do_api();
$helper->get_trj();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PHP+MYSQL+HTML百度地图打点示例.rar (4个子文件)
PHP+MYSQL+HTML百度地图打点示例
创建数据库测试数据脚本.sql 2KB
map
setPoint.php 2KB
bm.html 3KB
js
jquery-1.6.2.js 239KB
共 4 条
- 1
资源评论
- cole_cheng2021-05-21这能用?老子下载之后在phpmyadmin执行脚本创建了数据库,在php文件中配置好了连接信息,数据库什么的都没有弄错,屁用没有,HTML文件里面居然还有“这是在地图上打点,往里面传个经纬度即可,自己完善下循环就可以了”草了,怎么传,怎么完善,数据库里面读了七个数据,老子怎么知道哪个是哪个
大脑补丁
- 粉丝: 1w+
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功