Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv1952
Added Files:
db_dba.php
Log Message:
This is a database object that talks to Berkeley DB style databases
through the abstraction layer functions in PHP.
The most important options that this object is dependent on is:
'db_path' The path to the database.
'db_handler' The handler - could be 'gdbm'
--- NEW FILE ---
<?php
/**
* 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.
*
* @author Martin Geisler <[EMAIL PROTECTED]>
* @version $Id: db_dba.php,v 1.1 2001/04/02 19:29:03 gimpster Exp $
*/
class db_dba extends db_common {
/**
* Constructor
*
* We extend the defaults by setting the path to the databases to
'/tmp/phpweather.db'. You should use probably use another path, especially if you're
running Windows.
*
* @param array the initial properties of the object
*/
function db_dba($input) {
$this->defaults['db_path'] = '/tmp/phpweather.db';
$this->db_common($input);
}
/**
* Gets the type of the database.
*
* @return string The type of the database, 'mysql' in this case.
* @access public
*/
function get_type() {
return 'dba';
}
/**
* 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.
*
* @return boolean Returns true, if a connection were established, false otherwise.
* @access public
* @see disconnect()
*/
function connect() {
if ($this->is_connected) {
return true;
}
if (!$this->properties['db_pconnect']) {
return $this->is_connected = $this->link_id =
dba_open($this->properties['db_path'],
'w',
$this->properties['db_handler']);
} else {
return $this->is_connected = $this->link_id =
dba_popen($this->properties['db_path'],
'w',
$this->properties['db_handler']);
}
}
/**
* Disconnects from the database.
*
* If we're already disconnected from the database, this function will just return
true.
*
* @return boolean Since dba_close() doesn't return any value, this function
always returns true.
* @access public
* @see connect()
*/
function disconnect() {
if ($this->is_connected) {
dba_close($this->link_id);
$this->is_connected = false;
}
return true;
}
/**
* Inserts a METAR into the database.
*
* @param string The ICAO of the station.
* @param string The raw METAR.
* @param integer A standard UNIX timestamp.
* @access public
* @see update_metar()
*/
function insert_metar($station, $metar, $timestamp) {
dba_insert($station, $metar . ':' . $timestamp, $this->link_id);
}
/**
* Updates an existing METAR in the database.
*
* @param string The ICAO of the station.
* @param string The raw METAR.
* @param integer A standard UNIX timestamp.
* @access public
* @see insert_metar()
*/
function update_metar($station, $metar, $timestamp) {
dba_replace($station, $metar . ':' . $timestamp, $this->link_id);
}
/**
* Gets a METAR form the database.
*
* @param string The ICAO of the station.
* @return array The raw METAR and UNIX timestamp as an array, in that order.
* @access public
*/
function get_metar($station) {
if (dba_exists($station, $this->link_id)) {
$row = dba_fetch($station, $this->link_id);
$this->notice("Inserting this row into DBA database:<br><code>$row</code>");
return explode(':', $row);
} else {
return false;
}
}
}
?>
_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins