topical media & game development

talk show tell print

#mobile-ar-7-3.txt / txt



  // sample code 
  // misc snippets from chapter 7
  
  <?php
  /* Configure the connection to the MySQL database */
  /* add your details here */
  
  dbhost = “localhost”; /* your server name */
  dbdata = “database_name”; /* your database name */
  dbuser = “database_username”; /* the db username */
  dbpass = “database_password”; /* the db password */
  
  /* connect to the MySQL server. */
  db = new PDO( “mysql:host=dbhost; dbname=dbdata”, dbuser,
  dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => “SET NAMES utf8”) );
  
  // set the error reporting attribute to throw Exception .
  db->setAttribute( PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION );
  
  //The following code will read the query string and put the parameters into an array named
          value:
          // Put needed parameter names from GetPOI request in an array called keys.
          keys = array( “layerName”, “lat”, “lon”, “radius” );
          // Initialize an empty associative array.
          value = array();
          try {
                  // Retrieve parameter values using _GET and put them in value array with
                  // parameter name as key.
                  foreach( keys as key ) {
                          if ( isset(_GET[key]) )
                                  value[key] = _GET[key];
                          else
                                  throw new Exception(key .” parameter is not passed in GetPOI request.”);
                  }//foreach
          }//try
          catch(Exception e) {
          echo ‘Message: ‘ .e->getMessage();
          }//catch
  
  //Now you need to prepare your response that will display the POIs to the user:
  
          // Create an empty array named response.
          response = array();
          // Assign cooresponding values to mandatory JSON response keys.
  
          response[“layer”] = value[“layerName”];
          // Use Gethotspots() function to retrieve POIs with in the search range.
          response[“hotspots”] = Gethotspots( db, value );
          // if there is no POI found, return a custom error message.
                  if ( empty( response[“hotspots”] ) ) {
                          response[“errorCode”] = 20;
                          response[“errorString”] = “No POI found. Please adjust the range.”;
                  }//if
          else {
                  response[“errorCode”] = 0;
                  response[“errorString”] = “ok”;
          }//else
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.