- Introduction to PHP
- Arrays in PHP
- Communications with the server - GET and POST
- SQL and PHP data objects
- Accessing the database in PHP
- Introductions to AJAX
- Returning JSON data with AJAX
- Returning spatial data as geoJSON
PHP
is a server side scripting language
PHP is cross-platform and supported by all major web-servers
Syntax and functionality;
PHP can create a secure connection to a database in order to retrieve, query, update and delete the data within
We'll make a PHP-based webpage that embeds some data from our Postgres database
To create a connection to a PostgreSQL database the pg_connect()
function is used which takes the host name, database name, username and password as arguments and returns a pointer
to the database connection
Database is queried using the pg_query()
function which returns a resource containing the results of the query, known as the results set
pg_fetch_array()
function which returns the results row by rowpg_fetch_array()
accepts 3 arguments; the results set returned from pg_query(); the row number to fetch (if set to NULL or empty the next row is fetched) and the result type (in this case specified as an associative arrayjson_encode
is used to encode the data into JSON formatPHP script can be called from within a Javascript function
The advantage in doing this is that we can draw fresh results into a webpage without reloading the whole page (for example when a button is clicked or a dropdown menu is changed)
In order to do this we need to use something called an AJAX request
AJAX is a client side technique which allows data to be sent and retrieved from a server asynchronously
, that is, without interfering with the current webpage (i.e. it runs in the background)
An AJAX request can be embedded in a JavaScript function to either send data to a database or retrieve data from a database, without having to reload the page
getJSON()
function is called that returns JSON encoded data from the server using a HTTP GET requestgetJSON()
function accepts two arguments: a string containing a URL to which the request is sent and a callback function which is executed if the request succeedsAn associative array (also known as a map, dictionary or symbol table) is a collection of unique key-value pairs
, where each combination of key and value appears only once in the collection
Values can be extracted from an array through reference to their key just as values in a numeric array can be extracted based on their location in the array
JSON objects is a good example of this
A Web Mapping Service (WMS) is a service providing map data online for the use of other sites and applications
Web Mapping Services are based on the WMS standard , defined by the Open Geospatial Consortium (OGC), but other associated standards exist;
open data include
WMS defines a number of HTTP requests
and what the response should be
One of the foundational requests of a WMS-compliant map server is GetCapabilities
server=http://localhost:8080/geoserver/wms service=wms version=1.1.1 request=GetCapabilities
GitHub - GitHub offer free webspace through their GitHub Pages initiative
http://localhost:80/
as a URLOSGeo Live is an operating system designed for teaching and disseminating free open source software for geospatial applications
The package offers; map servers, desktop GIS and geographical database systems
Getting OSGeo Live
GeoServer and MapServer are the main two Open Source technologies for serving your own map files. Equivalent of ArcGIS Server
GeoServer is available on your OSGEO Live installation
Queries about this Lesson, please send them to:
*References*
- Google Maps; Power Tools for Maximizing the API, 2014
Evangelos Petroutsos
- D3 Tips and Tricks; Interactive Data Visualization in a Web Browser, 2013
Malcolm Maclean
- Interactive Data Visualization for the Web, 2013
Scott Murray
- Web Programming with HTML5, CSS, and JavaScript, 2019
John Dean
- Leaflet Documentation
Leaflet Team
- Google Documentation for developers
Google Team
Courtesy of …