A4.2 API to Add a Place |
|
Using the following to create an API named add_place.php. See this video for a description of the code below. The PHP program will accept a query string of name value pair arguments for (campus, cuisine, place), then call your stored procedure you created in the previous assignment. Alternatively you can write SQL statements to add a place without using your stored procedure. Your API should return a JSON object containing the error code and accompanying message. Use the same parameter names. <?php $user = '*****'; $campus = 'UHWO'; // Fill in with a campus when testing from the command line $cuisine = ''; $place = 'Himalayan Kitchen'; // Fill in with a place when testing from the command line if($campus>'' && $place>'') { $dsn = "mysql:host=$host;dbname=$database"; $statement = $pdo->prepare($sql); $statement = $pdo->query($sql); if ($rec = $statement->fetch()) { $out= json_encode( To test your API you can use the same tests you used to test your ADD_PLACE routine. First you may have to delete Himalayan Kitchen as the favorite Nepalese at UHWO if it is still present in your database.
|