Example #1
0
function zipcode_to_state($zip)
{
    global $_sql;
    try {
        establish_global_sqlwrap($_sql);
        $response = $_sql->query('SELECT state FROM ' . DATABASE_TABLE_ZIPCODE . ' WHERE zipcode=' . (int) $zip, ERROR_DATABASE_UPDATE);
        // No state for that zip?
        if (empty($response)) {
            throw new Exception('Zip code `' . $zip . '` does not exist in the zip code table.', ERROR_MISSING_DATA);
        }
    } catch (DatabaseException $e) {
        error_log_and_rethrow($e, ERROR_LOG_DATABASE);
    }
    // State exists, return it.
    return $response[0]['state'];
}
Example #2
0
 public static function zipcode2state($zip)
 {
     global $_sql;
     try {
         establish_global_sqlwrap($_sql);
         $response = $_sql->query('SELECT state FROM ' . DATABASE_TABLE_ZIPCODE . ' WHERE zipcode=' . (int) $zip, ERROR_DATABASE_UPDATE);
         // No state for that zip?
         if (empty($response)) {
             return false;
         }
     } catch (DatabaseException $e) {
         error_log_and_rethrow($e, ERROR_LOG_DATABASE);
     }
     // State exists, return it.
     return $response[0]['state'];
 }