PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

Страниц (1): [1]

> Найдено сообщений: 1
NewUserSince280716 Отправлено: 28 Июля, 2016 - 22:57:58 • Тема: Тестовое задание • Форум: Объектно-ориентированное программирование

Ответов: 18
Просмотров: 4543
Как вам мой вариант?
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. abstract class Logger{
  3.         protected $massege;
  4.         protected $log_time;
  5.         protected $host = 'localhost';
  6.         protected $user = 'root';
  7.         protected $password = '123';
  8.         protected $db = 'test';
  9.         public function get_date($error){
  10.                 @$this->log_time = date("[Y-m-d H:i:s]").serialize($error);
  11.         }
  12.         public function write_log_in_file(){
  13.         }
  14. }
  15. class FileLogger extends Logger{
  16.         private $way = 'log.txt';
  17.         public function write_log_in_file(){
  18.                 return file_put_contents($this->way, $this->log_time . "\n", FILE_APPEND);
  19.         }
  20. }
  21. class DBLogger extends Logger{
  22.         public function __construct($host = 'localhost', $user = 'root',$password = '123',$db = 'test'){
  23.                 $this->host = $host;
  24.                 $this->user = $user;
  25.                 $this->password = $password;
  26.                 $this->db = $db;
  27.         }
  28.         public function write_log_in_file(){
  29.                 $connect = mysqli_connect($this->host,$this->user,$this->password,$this->db);
  30.                 if (mysqli_connect_errno()) {
  31.                 printf("Connect failed: %s\n", mysqli_connect_error());
  32.                 exit();
  33.                 }
  34.                 $sql = mysqli_query($connect, "INSERT INTO Logg (massege) VALUES('error')");
  35.                 mysqli_close($connect);
  36.         }
  37. }
  38. $Log = new FileLogger('/log.txt');
  39. $Log->get_date('Error');
  40. $Log->write_log_in_file();
  41. $mysqliLog = new DBLogger();
  42. $mysqliLog->write_log_in_file();
  43. ?>

Страниц (1): [1]
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB