基于PostgreSQL+Postgis的空间数据库的实现(结合PHP)(3)
来源:互联网 发布:ubuntu挂载硬盘到home 编辑:程序博客网 时间:2024/05/22 05:02
PHP关于PostgreSQL的相关设置都弄好以后,就可以在PHP中直接操作数据库了。下面的一段代码是我将台风数据以点状数据全部插入到数据库中,其中包含:
- 数据库连接
- 文件打开并读取
- 消除字符串中多余的空格
- 执行sql查询
<?php//phpinfo();//连接数据库$conn = pg_connect("host=localhost port=5432 dbname=postgis user=postgres password=password");if ($conn) {print "OK! Has connected" . "<br>";} else {print "Error! Connect failure" . "<br>";}//文件打开$file = fopen("tydata2010.dat", "r") or exit("Unable to open file!");if($file){$arr_count = 1;while(!feof($file)){$str = trim(fgets($file));//去掉多余空格$str = preg_replace('/\s(?=\s)/', '', $str);//将字符串打散成数组$result = explode(" ", $str);echo print_r($result)."<br/>";//PostgreSQL中的插入语句为:insert into 表名 values(1,19631,'1963-04-13',40,'POINT(143.1 32.4)');$sql_insert_str="INSERT INTO typhoon VALUES(".$arr_count.",".$result[0].",'".$result[1]."-".$result[2]."-".$result[3]."',".$result[7].",'POINT(".$result[6]." ".$result[5].")');";//执行SQL插入$query_result = pg_query($conn,$sql_insert_str);if(!$query_result){echo "Query Failed!<br/>";}//echo $sql_insert_str."<br/>";$arr_count = $arr_count + 1;}echo "The total count is ".$arr_count;}else{echo "No data!";}fclose($file);?>
结合PHP对PostgreSQL的操作手册,貌似不需要关闭数据库连接,pg_close()并不很需要,因为非持久连接在本脚本执行结束后会自动关闭。
- 基于PostgreSQL+Postgis的空间数据库的实现(结合PHP)(3)
- 基于PostgreSQL+Postgis的空间数据库的实现(结合PHP)(1)
- 基于PostgreSQL+Postgis的空间数据库的实现(结合PHP)(2)
- PostgreSQL+PostGIS的使用 3
- PostGIS,ArcSDE For PostgreSQL,ArcEngine的关系与结合
- PostgreSQL+PostGIS的使用
- PostgreSQL+PostGIS的使用
- PostgreSql+PostGIS的安装
- PostgreSQL+PostGIS的使用
- postgresql+postgis空间数据库安装总结
- postgresql+postgis空间数据库使用总结
- 基于postgresql+postGIS+QGIS+MapServer的WebGIS部署
- 地图的开发研究--基于openlayers+geoserver+tomcat的离线地图--postgis空间数据库
- 地图的开发研究--基于openlayers+geoserver+tomcat的离线地图--postgis空间数据库
- PostgreSQL+PostGIS的使用 1
- PostgreSQL+PostGIS的使用 2
- PostgreSQL+PostGIS的使用 4
- PostgreSQL+PostGIS的使用 5
- Linux下VNC的配置
- LINUX 命令汇总
- jquery中cookie的使用方法
- 实现中文下的UITableView Index 分类
- python self
- 基于PostgreSQL+Postgis的空间数据库的实现(结合PHP)(3)
- 在Xcode中手动创建伪通用Framework
- Oracle 显示当前的所有用户表
- 黑马程序员 笔记(十)——面向对象(异常)
- Android 4.0新增WiFiDirect功能
- I am back
- Linux 汇编语言开发指南
- [leetcode] first missing positive
- 新手看招 Unix和Linux下C语言学习指南