PHP code example of zjkiza / sql-blade

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

    

zjkiza / sql-blade example snippets


    
    'paths' => [
        ...
        app_path('Sql/User'),
        ..
    ],


namespace App\Example;

use Zjk\SqlBlade\Contract\SqlBladeInterface;
use Doctrine\DBAL\Result;

class MyRepository {
    
    private SqlTwigInterface $sqlBlade;
    
    public function __construct(SqlBladeInterface $sqlBlade) 
    {
        $this->sqlBlade = $sqlBlade;
    }
    
    public function users(): array
    {
        return $this->sqlBlade->executeQuery('select_user', [
                'emails' => ['[email protected]', '[email protected]']
               ],[
                 'emails' => ArrayParameterType::STRING,
              ])->fetchAllAssociative()
    }    
    
    public function withTransaction(): array
    {
        $result = $this->sqlBlade->transaction(function (SqlBladeInterface $sqlBlade): Result {
            return $sqlBlade->executeQuery('select_without_blade');
        }, TransactionIsolationLevel::READ_UNCOMMITTED);

        return $result->fetchAllAssociative();
    }   
}