Source for file DBLogger.php

Documentation is available at DBLogger.php

  1. <?php
  2.  
  3. require_once "Logger.php";
  4.  
  5. final class DBLogger implements Logger
  6. {
  7.    const host='localhost';
  8.    const user='inventwrite';
  9.    const pass='PASSWORD2';
  10.    const db='opennac';
  11.    
  12.    private $conn=NULL;
  13.    private $stmt=NULL;
  14.    private $who=1;
  15.    private $host=NULL;
  16.    private $priority='info';
  17.    private $what=NULL;
  18.  
  19.    public function __construct()
  20.    {
  21.       if ($this->conn=new mysqli(self::host,self::user,self::pass,self::db))
  22.       {
  23.          $this->who=1;
  24.          $this->host='localhost';
  25.          $this->priority='info';
  26.          if ($this->stmt=$this->conn->prepare('insert into naclog set who=?, host=?,priority=?, what=?'))
  27.          {
  28.             $this->stmt->bind_param('isss',$this->who,$this->host,$this->priority,$this->what);
  29.          }
  30.       }
  31.    }
  32.    
  33.    public function log($message='')
  34.    {
  35.       if ($this->conn && $this->stmt && is_string($message&& (strlen($message)>0))
  36.       {
  37.          $this->what=$message;
  38.          $this->stmt->execute();
  39.          if ($this->stmt->affected_rows!=1)
  40.          {
  41.             #echo mysqli_error($this->conn);
  42.             return false;
  43.          }
  44.          $this->what=NULL;
  45.          return true;
  46.       }
  47.       return false;
  48.    }
  49.  
  50.    public function changePriority($string)
  51.    {
  52.       if (is_string($string&& (strlen($string)>0))
  53.       {
  54.          switch($string)
  55.          {
  56.             case 'info':
  57.             case 'err':
  58.             case 'crit':
  59.                $this->priority=$string;
  60.                break;
  61.          }
  62.          return true;
  63.       }
  64.       else return false;
  65.    }
  66. }
  67.  
  68. ?>

Documentation generated on Mon, 17 Nov 2008 01:10:28 +0100 by phpDocumentor 1.4.0