PHP code example of yiisoft / log-target-db

1. Go to this page and download the library: Download yiisoft/log-target-db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yiisoft / log-target-db example snippets


// Create db schema manager
$dbSchemaManager = new DbSchemaManager($db);

// Ensure table with default name
$dbSchemaManager->ensureTable();

// Ensure table with custom name
$dbSchemaManager->ensureTable('{{%custom_log_table}}');

// Ensure no table with default name
$dbSchemaManager->ensureNoTable();

// Ensure no table with custom name
$dbSchemaManager->ensureNoTable('{{%custom_log_table}}');

$dbTarget = new \Yiisoft\Log\Target\Db\DbTarget($db, $table);

$logger = new \Yiisoft\Log\Logger([$dbTarget]);

/**
 * @var \Yiisoft\Db\Connection\ConnectionInterface $mysqlDb
 * @var \Yiisoft\Db\Connection\ConnectionInterface $sqliteDb
 */

$logger = new \Yiisoft\Log\Logger([
    new \Yiisoft\Log\Target\Db\DbTarget($mysqlDb),
    new \Yiisoft\Log\Target\Db\DbTarget($sqliteDb),
]);