PHP code example of squidit / cycle-sql-tagger

1. Go to this page and download the library: Download squidit/cycle-sql-tagger 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/ */

    

squidit / cycle-sql-tagger example snippets




declare(strict_types=1);

use Cycle\Database\Config;
use SquidIT\Cycle\Sql\Tagger\DatabaseManagerWithTagger;
use SquidIT\Cycle\Sql\Tagger\DatabaseWithTagger;

/**
 * Set up your cycle/database configuration
 * 
 * Make sure you select the following driver: 
 * SquidIT\Cycle\Sql\Tagger\Driver\MySQL\MySQLTagDriver::class
 */
/** @var DatabaseConfig $dbConfig */
$dbConfig = new Config\DatabaseConfig([
            ...
            'connections' => [
                'mariaDbDsn' => new Config\MySQLDriverConfig(
                    ...
                    driver: MySQLTagDriver::class,
                    ...
                ),
            ],
        ]);

$dbal = new DatabaseManagerWithTagger($dbConfig);

$database = $dbal->database();
$database->tagQueryWithComment('Filename: file.php, Method: MethodName, LineNr: 10');
$database->query('SELECT [QUERY]');

// After executing a SQL query the comment is removed
$database->tagQueryWithComment('Filename: file.php, Method: MethodName, LineNr: 10');
$database->execute('INSERT [QUERY]');

// the following will have the same result
$database->tagQueryWithComment('Filename: file.php, Method: MethodName, LineNr: 10');
$selectQuery = $database->select();
$selectQuery->fetchAll();

# or:

$selectQuery = $database->select();
$selectQuery->tagQueryWithComment('Filename: file.php, Method: MethodName, LineNr: 10');
$selectQuery->fetchAll();

// After selecting a table
$database = $database->database();
$database->table('tableName')
    ->tagQueryWithComment([
        'File: ' . __FILE__,
        'Line: ' . __LINE__,
        'Function: ' . __METHOD__
     ])
    ->update([
        'column1' => 'value1',
        'column2' => 'value2',
    ])
    ->where([
        'comment_id' => ['=' => 1],
    ])
    ->run();