Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: /www/gimpster.com/php/phpweather/db/db_dba.php
PHP Weather - PHP Weather

db_dba

base_object
   |
  +-- db_common
     |
    +-- db_dba

This class is the 'dba' database-type. This type of database is a wrapper itself, so you have to pass a handler to it as the index 'db_handler', when you create it.

 

private class db_dba extends db_common

This class is the 'dba' database-type. This type of database is a wrapper itself, so you have to pass a handler to it as the index 'db_handler', when you create it.
It implements all the methods necessary to insert, update and retrive METARs using a Berkeley DB style database. This is a file-based database, so you have to make sure that you have write access to the directory where you place the database.

AuthorsMartin Geisler <gimpster@gimpster.com>
Versiondb_dba.html,v 1.4 2001/06/27 11:35:43 gimpster Exp

 

Methods inherited from db_common

db_common

Methods inherited from base_object

base_object, error, debug, print_properties

Public Method Summary

void

db_dba(array $input)

Constructor
string

get_type()

Gets the type of the database.
boolean

connect()

Establishes a connection to the database. It is assumed, that the database is already created.
boolean

disconnect()

Disconnects from the database.
void

insert_metar(string $station, string $metar, integer $timestamp)

Inserts a METAR into the database.
void

update_metar(string $station, string $metar, integer $timestamp)

Updates an existing METAR in the database.
array

get_metar(string $station)

Gets a METAR form the database.
string

lookup_icao(string $icao)

Translates an ICAO into a station name
array

get_countries()

Returns a list of available countries.
array

get_icaos(string $cc, string &$country)

Returns an array of stations.

Private Method Summary

bool

create_tables()

Creates the necessary files.
bool

insert_stations(array $data, array $countries)

Inserts the stations into the database.

Fields inherited from db_common

$is_connected, $link_id, $result_id

Fields inherited from base_object

$properties, $version

Private Field Summary

integer

$link_stations_id

A link ID to the stations database.
integer

$link_countries_id

A link ID to the countries database.

Public Method Details

db_dba

public void db_dba( array $input )

  Constructor

Parameter
array $input
initial properties of the object
Returns void


get_type

public string get_type( )

  Gets the type of the database.

Returns string

The type of the database, 'mysql' in this case.


connect

public boolean connect( )

  Establishes a connection to the database. It is assumed, that the database is already created.
If there has already been made a connection to the database, this function just returns true, and nothing will be changed. This means that it is safe to call this instead of testing $is_connected. If $properties['db_pconnect'] is true, then a persistent connection will be established. $db_hostname is used as the path for the database.

Returns boolean

Returns true, if a connection were established, false otherwise.

See Also disconnect()

disconnect

public boolean disconnect( )

  Disconnects from the database.
If we're already disconnected from the database, this function will just return true.

Returns boolean

Since dba_close() doesn't return any value, this function always returns true.

See Also connect()

insert_metar

public void insert_metar( string $station, string $metar, integer $timestamp )

  Inserts a METAR into the database.

Parameter
string $station
ICAO of the station.
string $metar
raw METAR.
integer $timestamp
standard UNIX timestamp.
Returns void

See Also update_metar()

update_metar

public void update_metar( string $station, string $metar, integer $timestamp )

  Updates an existing METAR in the database.

Parameter
string $station
ICAO of the station.
string $metar
raw METAR.
integer $timestamp
standard UNIX timestamp.
Returns void

See Also insert_metar()

get_metar

public array get_metar( string $station )

  Gets a METAR form the database.

Parameter
string $station
ICAO of the station.
Returns array

The raw METAR and UNIX timestamp as an array, in that order.


lookup_icao

public string lookup_icao( string $icao )

  Translates an ICAO into a station name
The boring ICAO (e.g. EKYT) is translated into something like 'Aalborg, Denmark'.

Parameter
string $icao
ICAO one want's to translate.
Returns string

The full name of the station, including country.


get_countries

public array get_countries( )

  Returns a list of available countries.

Returns array

An associative array with the country-codes as
the keys and the names of the countries as the
values.


get_icaos

public array get_icaos( string $cc, string &$country )

  Returns an array of stations.

Parameter
string $cc
country-code.
string &$country
parameter is passed by reference. The name
of the country that corresponds to the
country-code is stored here.
Returns array

An associative array with the ICAO as the key
and the name of the station as the values. The
name of the country is not added to the name of
the station.


Private Method Details

create_tables

private bool create_tables( )

  Creates the necessary files.

Returns bool

Returns true is the files were created, false otherwise.


insert_stations

private bool insert_stations( array $data, array $countries )

  Inserts the stations into the database.
It is assumed that create_tables() has been called previously (and that it returned true).

Parameter
array $data
three-dimensional array starts with a list of contry-codes. For each country-code the ICAOs and corresponding locations in that particular country are listed as key => value pairs.
array $countries
associative array with country-codes as the keys and the names of the countries as the values.
Returns bool


Private Field Details

$link_stations_id

private integer $link_stations_id

>><<

A link ID to the stations database.
We have to maintain a different link ID for each database used.


$link_countries_id

private integer $link_countries_id

>><<

A link ID to the countries database.
We have to maintain a different link ID for each database used.



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta