PHP Classes

File: examples/database_example.php

Recommend this page to a friend!
  Classes of Kiril Savchev   ITE Logger   examples/database_example.php   Download  
File: examples/database_example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: ITE Logger
Log messages to different storage PSR-3 compliant
Author: By
Last change:
Date: 7 years ago
Size: 827 bytes
 

Contents

Class file image Download
<?php

require_once '../vendor/autoload.php';

$dbConfig = [
       
'host' => 'localhost',
       
'name' => '{{DATABASE_NAME}}', // set your own here
       
'username' => '{{USERNAME}}', // set your own here
       
'password' => '{{PASSWORD}}', // set your own here
       
'options' => [
                \
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
       
]
];

/*
 *
 * You need to execute this query to use this logger:

CREATE TABLE logs(
        id INT(11) NOT NULL AUTO_INCREMENT,
        message VARCHAR(255) NOT NULL,
        level VARCHAR(10) NOT NULL,
        date DATETIME NOT NULL,
        context TEXT,
        PRIMARY KEY(ID)
);

*/

$logger = new Ite\Logger\PdoMysqlLogger($dbConfig);
$logger->info("Testing database", ['key1' => 'value1']);
$logger->alert("Testing database", ['alert' => 'alerting']);