Pereiti prie turinio

Zocislovski

Nariai
  • Pranešimai

    3
  • Užsiregistravo

  • Lankėsi

  • Atsiliepimai

    0%

Zocislovski Pranešimai

  1. Sveiki, gal kas galėtumėte padėti ir pažiūrėti kas čia ne taip?:

     

    config.php

    <?php
    
    
    
    $host = 'localhost';
    $db = 'logger';
    $user = 'root';
    $pwd = 'user';
    
    $path = '/logs';
    

     

    logger.php

    <?php
    interface loggerInterface {
    
       public function __construct($saving_type);
    
    }
    
    abstract class partOfLogger {
    
       abstract function mysql($some_text);
    
       abstract function file($some_text);
    
    
    }
    
    class loggerSettings extends partOfLogger implements loggerInterface {
    
       var $savingType;
       var $host;
       var $db;
       var $user;
       var $pwd;
       var $path;
    
       public function __construct($saving_type) {
           switch($saving_type) {
               case "mysql":
                   $this->savingType = 1;
               break;
               case "file":
                   $this->savingType = 2;
               break;
               default:
                   $this->savingType = 0;
           }
           include("config.php");
           $this->host = $host;
           $this->db = $db;
           $this->user = $user;
           $this->pwd = $pwd;
           $this->path = $path;
       }
    
       function datetime() {
           return date("Y-m-d H:i:s");
       }
    
       function text($some_text) {
           $all = $this->datetime();
           $all .= ": ";
           $all .= $some_text;
           return $all;
       }
    
       function mysql($some_text) {
           $con = mysql_connect($this->host, $this->user, $this->pwd) or die(mysql_error());
           mysql_select_db($this->db, $con) or die(mysql_error());
           mysql_query("
           INSERT INTO  logs ('id', 'value') VALUES (NULL ,  ".$this->datetime().": ".$some_text.")");
    
       }
    
       function file($some_text) {
    
           $file = $this->path."/log.txt";
           $info = $this->text($some_text);
           $action = fopen($file, "a");
           fwrite($action, "$info\n");
           fclose($action);
       }
    }
    
    class Logger extends loggerSettings {
    
       public function log($information) {
           if ($this->savingType = 1) parent::mysql($information);
           if ($this->savingType = 2) parent::file($information);
           if ($this->savingType = 0) echo "Logs saving type is unset.";
       }
    
    

     

    vykdyti.php

    include 'logger.php';
    
    $logger = new Logger('mysql');
    $logger->log("bla bla bla");
    
    unset($logger);
    
    $logger = new Logger('file');
    $logger->log("bla bla bla");
    

     

    localhost'e paleidus failą vykdyti.php gaunamos klaidos:

     

    Warning: fopen(/logs/log.txt) [function.fopen]: failed to open stream: No such file or directory in /srv/www/development/other/__oth/logger/logger.php on line 75
    
    Warning: fwrite() expects parameter 1 to be resource, boolean given in /srv/www/development/other/__oth/logger/logger.php on line 76
    
    Warning: fclose() expects parameter 1 to be resource, boolean given in /srv/www/development/other/__oth/logger/logger.php on line 77
    
    
    

×
×
  • Pasirinkite naujai kuriamo turinio tipą...