php 随机经纬度,随机像mariadb插入10万数据,包括经纬度以及调用百度map API获取省份...

这段PHP代码展示了如何连接到MySQL数据库并执行删除操作,然后生成随机的时间戳、经度、纬度和省份信息,并将这些数据插入到`tongji`表中。代码还包含了用于生成随机时间、经纬度和省份的辅助函数,以及进行浮点数范围随机取值的函数。整个过程循环执行多次,用于批量生成测试数据。
摘要由CSDN通过智能技术生成

$link=mysqli_connect("localhost","root","dengli","yilonggu");

$link->query("delete from message");

function suijishijian()

{

$month=array('0','01','02','03','04','05','06','07','08','09','10','11','12');

$days=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');

$hour=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','00');

$fz=array("","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59");

$day=array(

"01"=>"31",

"02"=>"28",

"03"=>"31",

"04"=>"30",

"05"=>"31",

"06"=>"30",

"07"=>"31",

"08"=>"31",

"09"=>"30",

"10"=>"31",

"11"=>"30",

"12"=>"31");

$y=rand(2010,2013);

$m=$month[rand(1,12)];

$d=$days[rand(1,$day["$m"])];

$h=$hour[rand(1,24)];

$mm=$fz[rand(1,60)];

$s=$fz[rand(1,60)];

return "$y-$m-$d $h:$mm:$s\n";

}

function floadNumber($min,$max)

{

return $min + mt_rand() / mt_getrandmax() * ($max - $min);

}

function shengfen($jd,$wd)

{

$url="http://api.map.baidu.com/geocoder?location={$wd},{$jd}&output=json";

$json=json_decode(file_get_contents($url),TRUE);

return $json['result']['addressComponent']['province'];

}

for($i=1;$i<10000;$i++)

{

$zid=rand(1,99999);

$time=suijishijian();

$jingdu=floadNumber(100,120);

$weidu=floadNumber(30,40);

$province=shengfen($jingdu,$weidu);

$lid=rand(1,13);

$type=rand(0,3);

$tag=rand(1,4);

$sbh=md5(time());

$sql="insert into `tongji` (zid,time,jingdu,weidu,province,lid,type,tag,sbh) VALUES ('{$zid}','{$time}','{$jingdu}','{$weidu}','{$province}','{$lid}','{$type}','{$tag}','{$sbh}')";

$link->query($sql);

echo $sql."\n";

}

$link->close();

?>

这个数据表的结构,截图如下

标签:PHP

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值