In phpclasses/db.class.php: Added the database connection string as
authorarjen <arjen>
Sat, 29 Mar 2003 08:33:20 +0000 (08:33 +0000)
committerarjen <arjen>
Sat, 29 Mar 2003 08:33:20 +0000 (08:33 +0000)
an argument to the function copy_db_class.
Fixed the PHP member function db::db_connect(). The Postgres connection
string is now passed as an argument to that function.

src/gcm_daemon/gcm_daemon.php
src/phpclasses/db.class.php
src/phpclasses/db.postgres.php

index 1ed9bc9..c83c654 100755 (executable)
    Gnucomo-0.0.3: December 6th 2002
 
  $Log: gcm_daemon.php,v $
- Revision 1.9  2003-02-21 08:37:59  arjen
+ Revision 1.10  2003-03-29 08:33:58  arjen
+ In phpclasses/db.class.php: Added the database connection string as
+ an argument to the function copy_db_class.
+ Fixed the PHP member function db::db_connect(). The Postgres connection
+ string is now passed as an argument to that function.
+
+ Revision 1.9  2003/02/21 08:37:59  arjen
  Added new table to the database: log_adv_daemon_email.
 
 
 */
 
-// $Id: gcm_daemon.php,v 1.9 2003-02-21 08:37:59 arjen Exp $
+// $Id: gcm_daemon.php,v 1.10 2003-03-29 08:33:58 arjen Exp $
 
 ini_set('include_path', '.:./classes:../phpclasses');
 
@@ -42,7 +48,7 @@ require_once "gnucomo.process_log.php";
 $project_name  = "gnucomo";    //name of the entire project
 $app_name      = "gcm_daemon"; //name of the application running
 $developrelease = "TRUE";      //Indicates if special debug settings are needed
-$db_version    = 32;           //The db_version indicates what the level of 
+$db_version    = 36;           //The db_version indicates what the level of 
                                //the database should be. If the database is 
                                //old an update will be generated.
 $gcmd_version   = 3;           //This value indicates the active version of the gcm_daemon,
@@ -57,7 +63,6 @@ set_time_limit(0);
 // Read the database settings //
 $class_settings = new gnucomo_config();
 $class_settings->read($project_name);
-$class_settings->database();
 
 //Open an connection to the database
 $dbms_type = $class_settings->find_parameter("database", "type");
@@ -72,13 +77,13 @@ $dbms->db_host = $dbms_host;
 $dbms->db_name = $dbms_name;
 $dbms->db_user = $dbms_user;
 $dbms->db_password = $dbms_password;
-$dbms->db_connect();
+$dbms->db_connect($class_settings->database());
 
 if ($dbms->have_db_connection() == "FALSE") {
   exit ("Database connection failed.");
 } else {
   //The database connection has been made.
-  $dbms_working = copy_db_class($dbms);
+  $dbms_working = copy_db_class($dbms, $class_settings->database());
 }
 
 //Verify if the database is up-to-date by checking the versionnumber
@@ -145,6 +150,7 @@ function process_log () {
   */
   global $dbms;
   global $dbms_working;
+  global $class_settings;
 
   //Find records in log that still have to be processed.
 
@@ -160,8 +166,8 @@ function process_log () {
   $dbms->query($local_sql);
 
   //Update the log-statistics in the object-table 
-  $local_statistics_db = copy_db_class($dbms);
-  $local_findobject_db = copy_db_class($dbms);
+  $local_statistics_db = copy_db_class($dbms, $class_settings->database());
+  $local_findobject_db = copy_db_class($dbms, $class_settings->database());
 
   //Make totals 
   $local_upper_row = $dbms->num_rows() + $last_log + 1;
@@ -183,7 +189,7 @@ function process_log () {
   if ($dbms->num_rows() > 0) {
 
     //Create a database connection for changes in the database.
-    $dbms_changes = copy_db_class($dbms);
+    $dbms_changes = copy_db_class($dbms, $class_settings->database());
     if ($dbms_changes->have_db_connection() == 'TRUE') {
 
        $local_sql               = 0 ;     
@@ -258,12 +264,12 @@ function notificationstats () {
  * OUTPUT : NONE
  */
            
- global $dbms;
+ global $dbms, $class_settings;
 
  //Find records in log that still have to be processed.
  $local_sql = "SELECT setting_value FROM db_value WHERE setting = 'last_notification'";
  $dbms->query($local_sql);
- $local_dbms = copy_db_class($dbms);
+ $local_dbms = copy_db_class($dbms, $class_settings->database());
 
  //Determine the last notification
  if ($dbms->fetch_row() == "TRUE") {
index f93fa77..a52f2b1 100644 (file)
@@ -39,7 +39,7 @@
        require_once ("db.".$local_db_type.".php");
       }
 
-   function copy_db_class ($inp_class) {
+   function copy_db_class ($inp_class, $connection_string) {
    /* This function takes a database class, sets the values for the connection,
     * opens the connection and returns the new cloned class
     * INPUT    : inp_class   - Typically a database class
@@ -51,7 +51,7 @@
     $new_class->db_name     = $inp_class->db_name;
     $new_class->db_user     = $inp_class->db_user;
     $new_class->db_password = $inp_class->db_password;
-    $new_class->db_connect();
+    $new_class->db_connect($connection_string);
     return $new_class;
 
    }
index 0fc268c..e8e911c 100644 (file)
    var $db_row_number;    //The row-number that is currently active
    var $db_result_row;    //Array with in each element a field of the result
 
-   function db_connect () {
+   function db_connect ($connection_string)
+   {
     /* This function makes the connection to the database. It will look at the selected DBMS. 
      * It will detected if password or hostname is missing and leave that out of the string.
-     * INPUT: NONE (all defined in the class)
+     * INPUT: NONE (The database connection string)
      * OUTPUT: NONE
      */ 
-     $local_connection_string = '';
-     if ($this->db_host == '') {
-        $local_connection_string .= "host=$this->db_host ";
-     }
     
-     $local_connection_string = "dbname=$this->db_name user=$this->db_user ";
-
-     if ($this->db_password == '') {
-        $local_connection_string .= $this->db_password;
-     }
+       $this->db_connection = pg_pconnect($connection_string);
 
-       $this->db_connection = pg_pconnect($local_connection_string);
-       if ($this->have_db_connection() == FALSE) {
+       if ($this->have_db_connection() == FALSE)
+        {
           syslog (LOG_INFO, "Failed to make a connection to Postgres");
            die ("connection to Postgres failed\n");
-       } else {
+       }
+        else
+        {
           syslog (LOG_INFO, "Connection to Postgres was made correctly");
        }
    }