CVS: phpweather/db pw_db_mysql.php,1.4,1.5
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-05-20 15:48:51
|
Update of /cvsroot/phpweather/phpweather/db In directory usw-pr-cvs1:/tmp/cvs-serv27357 Modified Files: pw_db_mysql.php Log Message: Some minor changes I made while I made the PostgreSQL backend. It's now possible to use a non-standard port - that was ignored before. Index: pw_db_mysql.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/db/pw_db_mysql.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- pw_db_mysql.php 26 Mar 2002 18:52:43 -0000 1.4 +++ pw_db_mysql.php 20 May 2002 15:48:48 -0000 1.5 @@ -5,7 +5,9 @@ /** * This class is the 'mysql' database-type. * - * It implements all the methods necessary to insert, update and retrive METARs using a MySQL database. You'll need access to a MySQL database to be able to use this object. + * It implements all the methods necessary to insert, update and + * retrive METARs using a MySQL database. You'll need access to a + * MySQL database to be able to use this object. * * @author Martin Geisler <gim...@gi...> * @version $Id$ @@ -13,8 +15,8 @@ class pw_db_mysql extends pw_db_common { /** - * This constructor does nothing besides calling the parent - * constructor. + * This constructor makes sure that the MySQL extension is loaded + * and then calls the parent constructor. * * @param array the initial properties of the object */ @@ -60,14 +62,24 @@ if ($this->is_connected) { return true; } + + if (empty($this->properties['db_port'])) + /* Default MySQL port: */ + $port = 3306; + else + $port = $this->properties['db_port']; + + if (!$this->properties['db_pconnect']) { - $this->link_id = mysql_connect($this->properties['db_hostname'], - $this->properties['db_username'], - $this->properties['db_password']); + $this->link_id = + mysql_connect($this->properties['db_hostname'] . ':' . $port, + $this->properties['db_username'], + $this->properties['db_password']); } else { - $this->link_id = mysql_pconnect($this->properties['db_hostname'], - $this->properties['db_username'], - $this->properties['db_password']); + $this->link_id = + mysql_pconnect($this->properties['db_hostname'] . ':' . $port, + $this->properties['db_username'], + $this->properties['db_password']); } if ($this->link_id) { $this->is_connected = true; @@ -224,7 +236,7 @@ /* First we make a table for the METARs */ $this->query('DROP TABLE IF EXISTS ' . $this->properties['db_metars']); $this->query('CREATE TABLE ' . $this->properties['db_metars'] . '( - icao varchar(4) NOT NULL, + icao char(4) NOT NULL, metar varchar(255) NOT NULL, timestamp timestamp(14), PRIMARY KEY (icao), @@ -233,7 +245,7 @@ /* Then we make a table for the stations. */ $this->query('DROP TABLE IF EXISTS ' . $this->properties['db_stations']); $this->query('CREATE TABLE ' . $this->properties['db_stations'] . '( - icao varchar(4) NOT NULL, + icao char(4) NOT NULL, name varchar(255) NOT NULL, cc char(2) NOT NULL, country varchar(128) NOT NULL, @@ -258,7 +270,7 @@ function lookup_icao($icao) { $this->query('SELECT name, country FROM ' . $this->properties['db_stations'] . " WHERE icao = '$icao'"); - if ($this->num_rows()) { + if ($this->num_rows() == 1) { $row = $this->fetch_row(); return "$row[0], $row[1]"; } else { |