The form itself includes a call to the fmExecuteSQL function, using a static SELECT statement 
			to generate the list of the states referenced in the database. 
			
			It also makes use of FMWebFrame's caching function. If available, the list of states
			is pulled from the cache.
*/
// Initialize the request.
require_once dirname(__FILE__) . '/../FMWebFrame/FMWebFrame.php';
// Check to see if there is a list of states in the cache.
$states_cache = fmCacheGet('states');
// If there is no cached list of states, or the cache is more than 30 days old...
if ($states_cache === null or $states_cache['Cache_Age'] > 60 * 60 * 24 * 30) {
    // Get a list of the states that are referenced in the Contacts table.
    $states = fmExecuteSQL($fmDemo, 'SELECT DISTINCT State FROM Contacts ORDER BY State');
    // Cache the list.
    fmCachePut($states, 'states');
} else {
    // Get the content of the cache.
    $states = $states_cache['Cache_Contents'];
}
// Set page title.
$ui_title = "FMWebFrame Demo | ExecuteSQL";
// Start output buffering.
ob_start();
?>

<h1>ExecuteSQL</h1>

<p>With FMWebFrame's "fmExecuteSQL" function, you can query FileMaker databases using SQL Select statements directly from your Web solutions. The SELECT statements can be static (like the one used to generate the list of states in the form below) or dynamically generated (based on user criteria).</p>
<p>To give fmExecuteSQL a try, enter some search criteria using the form below. For example, search for the last name of: Smith</p>
$current_time = explode(' ', $current_time);
$current_time = $current_time[1] + $current_time[0];
$page_start_time = $current_time;
// Get a list of the states that are referenced in the Contacts table.
$state_counts = fmExecuteSQL($fmDemo, 'SELECT State, COUNT(*) FROM Contacts GROUP BY State ORDER BY State');
// Get the stop time.
$current_time = microtime();
$current_time = explode(' ', $current_time);
$current_time = $current_time[1] + $current_time[0];
$page_stop_time = $current_time;
// Get the elapsed time.
$page_elapsed_time = round($page_stop_time - $page_start_time, 4);
// Get a unique ID for this example.
$uuid = uniqid();
// Cache the results.
fmCachePut($state_counts, 'state_counts_' . $uuid);
// Set page title.
$ui_title = "FMWebFrame Demo | Caching";
// Start output buffering.
ob_start();
echo '<h1>Caching</h1>';
echo '<p>The data used in the table below was <b>not</b> pulled from the cache, and that is why it took so long for the page to load. ';
echo 'In fact, <b>it took ' . $page_elapsed_time . ' seconds</b> just to obtain the data from the database server.';
echo '</p>';
echo '<p>';
echo 'In this example, an ExecuteSQL call was made with this SELECT statement: SELECT State, COUNT(*) FROM Contacts GROUP BY State ORDER BY State. (The demo database includes over 25,000 sample contact records.)';
echo '</p>';
echo '<p>To see how much faster the page loads when the cache is used, ';
echo '<a href="cache-handler-with-cache.php?uuid=' . $uuid . '&elapsed=' . $page_elapsed_time . '">click here</a>.</p>';
echo '<table class="gridtable">';
echo '<tr>';