host = $host; $this->db = $database; $this->user = $user; $this->pass = $password; $this->link = mysql_connect($this->host, $this->user, $this->pass); if( $this->link ) mysql_select_db($this->db); } function close() { if( $this->link ) { if( ! mysql_close( $this->link ) ) { //echo "mysql_close failure for link resource ".$this->link." ".var_dump(debug_backtrace()); } $this->host = ""; $this->db = ""; $this->user = ""; $this->pass = ""; $this->link = NULL; } $this->endlog(); // stop the logger... } /* * open a logfile using the default or a custom path for this instance * parameter = optional relative logfile name otherwise my default of ql.txt in the web/cgi-bin is used */ function startlog($filename="") { $this->endlog(); // just in case... if( ! $filename ) { $filename = $_SERVER['DOCUMENT_ROOT']."/cgi-bin/ql.txt"; } $this->logfile = fopen( $filename, "a" ); } /* startlog */ /* * writes the passed event text to the logger. Optional comment is appended to the date/time/caller line above. * */ function writelog($event,$comment="") { $openclose = false; if( ! $this->logfile ) { $this->startlog(); $openclose = true; } if( $this->logfile ) { $entry = "\n# ".date("Y/m/d H:i:s "); $entry .= " IP: [".$_SERVER['REMOTE_ADDR']."] URL: ".$_SERVER['SCRIPT_NAME']; if( $_SERVER['QUERY_STRING'] ) $entry .= "?".$_SERVER['QUERY_STRING']; if( $comment ) $entry .= "\n# ".$comment; $entry .= "\n".$event.";\n\n"; fwrite( $this->logfile, $entry ); } if( $openclose ) { $this->endlog(); } } /* * closes the simple logger file and resets the instance handle. * */ function endlog() { if( $this->logfile ) { fclose( $this->logfile ); $this->logfile = NULL; } } } ?>