PHP code example of adgoal / dbal-fault-tolerance
1. Go to this page and download the library: Download adgoal/dbal-fault-tolerance 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/ */
adgoal / dbal-fault-tolerance example snippets
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
$config = new Configuration();
//..
$connectionParams = array(
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
// [dbal-fault-tolerance] settings
'wrapperClass' => Adgoal\DBALFaultTolerance\Connection::class,
'driverClass' => Adgoal\DBALFaultTolerance\Driver\PDOMySql\Driver::class,
'driverOptions' => [
'x_reconnect_attempts' => 3,
'force_ignore_transaction_level' => true
]
);
$conn = DriverManager::getConnection($connectionParams, $config);
//..
return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => \Adgoal\DBALFaultTolerance\Driver\PDOMySql\Driver::class,
'wrapperClass' => \Adgoal\DBALFaultTolerance\Connection::class,
'params' => [
'host' => 'localhost',
'port' => '3307',
'user' => '##user##',
'password' => '##password##',
'dbname' => '##database##',
'charset' => 'UTF8',
'driverOptions' => [
'x_reconnect_attempts' => 9,
'force_ignore_transaction_level' => true
]
],
],
],
],
];
$em->getConnection()->refresh();