You are here

Adding Function() & Arguments check to PHP scripts

Finished week seven continue working with my PHP script from last week, and by doing that I had more command functions to final__params.php. Charles had me add in function() and argument check to php script to make sure that the script is gathering data from the database server. 

From there I created a test file to print out the results from my PHP scripts, and by doing that I made ./test.bat. With this test file it has all the functions like the: variable, assetype, asset, request, station, and offering from final__params.php.

Charles had task for me to do to insert the Function() commands:

  1. Remove the print lines that we added to debug the code.
  2. Add the glider and vessel test lines to test.bat
  3. Run test.bat and see if the glider and vessel section of the code produces results that match what you get from the data_availability.php urls that you get in the Web Console.
  4. If not, debug the glider and vessel section to get the same results.

    • One difference I think you'll get is that the 'collection' column won't give the same results as the columns that are used in the queries in data_availability.php
    • Check if any of the other columns besides collection give anything useful
    •  Look at the collection result and see if it can be reduced down to something similar to what data_availability.php gives.
    • The match between what your code gives for the name of the mission and what data_availability.php gives does not need to be exact
  5. Develop more tests of the code and document where the results match and where they don't

Argument check commands:

  1. Develop script that takes an array of arguments and runs both final__params.php and data_availability.php using the same arguments, and checks if the results are the same or different.
  2. Create a test list of arguments to run through the testing script

    • the test list should include all the offerings/variables and all the vessels and the glider. We can get the list of offerings and a list of all the vessels from the database.
    • the test list should also include some fake offerings to make sure that the two scripts also return the same results for bad url arguments.
  3. We know that one of the differences in results we will see is that the verified data is missing from the datanearhere metadata, so we need to modify the code that generates the datanearhere metadata to read the verified data.
  4. We know that there is another case where the results should differ because data_availability.php produces the wrong answer, so we should confirm that the results actually differ in that case and that the new results are correct

For stations, check both the $offering and the $variable are valid use:

$sql = select count(*) from integrated.offering where offering = 'saturn03.240.A.CT';
$sql = select count(*) from integrated.offeringvariable where offering = 'saturn03.240.A.CT' and variable = 'salt';
in php, replace the '' quoted string with \$1 and \$2

for glider, use the same query (with $asset instead of $offering as the parameter)

$sql = select count(*) from integrated.offering where offering = 'phoebe';
replace the '' quoted string with \$1

for vessels, use

$sql = select count(*) from cruise.vessel where vessel = 'Barnes';
with $asset as the parameter
replace the '' quoted string with \$1

I insert the remaining command to each $sql in station, glider and vessel:

$params = array($asset);
$results = pg_query_params($db,$sql,$params);
$row = pg_fetch_array($results);
if ($row == 0) { return json_encode(array("status"=>"bad asset argument"));}

By inserting the following commands to PHP script will identify the argument is correct and gaves you a results from the datanearhere.metadata that I am working with. I got confused on the arguments check command because I wasn't sure if I was inserting the right command for each section. 

After Charles explained what was going on with the commands, it all made sense to me know how come to make sure it goes you the right call back when you want to see if your code is executing correctly. 

Now we're making sure that the test file is printing the same data from the existing data from the servers on file. Getting more into the final stage for my PHP script. Looking forward to what next week has to bring to the table.