PHP code example of bauhaus / dbasserture

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

    

bauhaus / dbasserture example snippets


use Bauhaus\DbAsserture\DbAssertureFactory;

$factory = new DbAssertureFactory();
$dbAsserture = $factory->fromDsn('mysql://user:pass@host:port/dbname');

// Clean tables
$dbAsserture->clean('table_name', 'another_table_name');

// Insert registers
$dbAsserture->insert('table_name', ['id' => 1, 'name' => 'Name']);
$dbAsserture->insert('table_name',
    ['id' => 1, 'name' => 'Name'],
    ['id' => 2, 'name' => 'Another name'],
);

// Select registers
$dbAsserture->select('table_name', ['name' => 'John']); // return many registers with all fields matching provided filter
$dbAsserture->selectOne('table_name', ['id' => 1]); // return one register with all fields matching provided filters

// Assert if is registered in database
$dbAsserture->assertOneIsRegistered('table_name', ['id' => 1, 'name' => 'Name']); // return true or throw exception