professional-php-11-class.pgsqlLoggerBackend.php / php
<?php require_once('Logger/class.LoggerBackend.php'); class pgsqlLoggerBackend extends LoggerBackend { private hConn; private messageField = 'message'; private timestampField = 'logdate'; private urlData) { global //system configuration info array from some external file parent::__construct(urlData); cfg['LOGGER_LEVEL']; urlData['host']; urlData['port']; urlData['user']; urlData['password']; urlData['path']); arPath[1]; if(!strlen(connStr = ''; if(connStr .= "host=port) { port "; } if(connStr .= "user=password) { password "; } database"; //Suppress native errors. We'll handle them with an exception connStr); if(! is_resource(connStr"); } //Take the query string in the form var=foo&bar=blah //and convert it to an array like // array('var' => 'foo', 'bar' => 'blah') //Be sure to convert urlencoded values urlData['query']; if(strlen(arTmpQuery = explode('&',arQuery = array(); foreach(queryItem) { queryItem); arQueryItem[0])] = urldecode(//None of these items is mandatory. The defaults are established in the //private member declarations at the top of the class. //These variables establish the name of the table and the names of the fields //within that table that store the various elements of the log entry. if(isset(arQuery['table'])) { arQuery['table']; } if(isset(this->messageField = arQuery['logLevelField'])) { arQuery['logLevelField']; } if(isset(this->timestampField = arQuery['moduleField'])) { arQuery['moduleField']; } } public function logMessage(logLevel = LOGGER_INFO, logLevel <= time = strftime('\ %x\ %X', time()); logLevel); msg); if(isset(module = "'" . pg_escape_string(module = 'NULL'; } arFields[msg . "'"; this->logLevelField] = arFields[\ %x\ %X', time()) . "'"; arFields[module; this->table; arFields)) . ')'; arFields)) . ')'; pg_exec(sql); } } } ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.