PHP code example of germania-kg / databases

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

    

germania-kg / databases example snippets



use Germania\Databases\DatabasesServiceProvider;

// A. Use with Slim or Pimple
$app = new \Slim\App;
$dic = $app->getContainer();
$dic = new Pimple\Container;

// B. Register Service Provider.
// see https://pimple.symfony.com/#extending-a-container
// Optionally pass custom PDO error mode
$dic->register( new DatabasesServiceProvider );
$dic->register( new DatabasesServiceProvider( \PDO::ERRMODE_EXCEPTION ) );


$db = [
	'dsn' => "mysql:host=localhost;dbname=MyDatabase;charset=utf8",
	'user' => "username",
	'pass' => "secret"
];

// Grab Factory
$pdo_factory = $dic['PDO.Factory'];

// Create handler
$pdo = $pdo_factory( $db );
$pdo = $pdo_factory( (object) $db ); // StdClass objects
$pdo = $pdo_factory( new \ArrayObject($db) ); // ArrayAccess instance

$dic->extend(PDO.ErrorMode', function($default_error_mode, $dic) {
    return \PDO::ERRMODE_SILENT;
});

$pdo_options = $dic['PDO.Options'];

$dic->extend('PDO.Options', function($default_options, $dic) {
    return array_merge( $default_options, array(
    	\PDO::ATTR_ERRMODE => \PDO::ERRMODE_SILENT
    	// custom values here
    ));
});