Add IBM_DB2 support
This commit is contained in:
parent
fed6ccfc27
commit
b4407e6bc1
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "cooperl/laravel-db2",
|
"name": "leenooks/laravel-db2",
|
||||||
"description": "laravel-db2 is a simple DB2 service provider for Laravel. It provides DB2 Connection by extending the Illuminate Database component of the laravel framework.",
|
"description": "laravel-db2 is a simple DB2 service provider for Laravel. It provides DB2 Connection by extending the Illuminate Database component of the laravel framework.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"laravel",
|
"laravel",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3",
|
"php": "^7.4|^8.0",
|
||||||
"illuminate/database": "^8.0"
|
"illuminate/database": "^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
@ -26,6 +26,13 @@ class DB2ServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected $defer = false;
|
protected $defer = false;
|
||||||
|
|
||||||
|
private const drivers = [
|
||||||
|
'pdo_ibm',
|
||||||
|
'db2_ibmi_odbc',
|
||||||
|
'db2_zos_odbc',
|
||||||
|
'db2_expressc_odbc',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap the application events.
|
* Bootstrap the application events.
|
||||||
*
|
*
|
||||||
@ -52,19 +59,14 @@ class DB2ServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// Extend the connections with pdo_odbc and pdo_ibm drivers
|
// Extend the connections with pdo_odbc and pdo_ibm drivers
|
||||||
foreach (config('database.connections') as $conn => $config) {
|
foreach (config('database.connections') as $conn => $config) {
|
||||||
|
|
||||||
// Only use configurations that feature a "odbc", "ibm" or "odbczos" driver
|
// Only use configurations that feature a "odbc", "ibm" or "odbczos" driver
|
||||||
if (!isset($config['driver']) || !in_array($config['driver'], [
|
if (! isset($config['driver']) || ! in_array($config['driver'],self::drivers))
|
||||||
'db2_ibmi_odbc',
|
|
||||||
'db2_ibmi_ibm',
|
|
||||||
'db2_zos_odbc',
|
|
||||||
'db2_expressc_odbc',
|
|
||||||
])
|
|
||||||
) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// Create a connector
|
// Create a connector
|
||||||
$this->app['db']->extend($conn, function($config, $name) {
|
$this->app['db']->extend($conn,function($config,$name) {
|
||||||
|
$config = array_merge($config,config('db2.drivers.'.$config['driver']));
|
||||||
$config['name'] = $name;
|
$config['name'] = $name;
|
||||||
switch ($config['driver']) {
|
switch ($config['driver']) {
|
||||||
case 'db2_expressc_odbc':
|
case 'db2_expressc_odbc':
|
||||||
@ -84,7 +86,7 @@ class DB2ServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
$db2Connection = $connector->connect($config);
|
$db2Connection = $connector->connect($config);
|
||||||
|
|
||||||
return new DB2Connection($db2Connection, $config["database"], $config["prefix"], $config);
|
return new DB2Connection($db2Connection,$config['database'],$config['prefix'],$config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ class DB2ServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
if ($this->app instanceof LaravelApplication) {
|
if ($this->app instanceof LaravelApplication) {
|
||||||
return config_path('db2.php');
|
return config_path('db2.php');
|
||||||
|
|
||||||
} elseif ($this->app instanceof LumenApplication) {
|
} elseif ($this->app instanceof LumenApplication) {
|
||||||
return base_path('config/db2.php');
|
return base_path('config/db2.php');
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,12 @@ class IBMConnector extends DB2Connector
|
|||||||
*/
|
*/
|
||||||
protected function getDsn(array $config)
|
protected function getDsn(array $config)
|
||||||
{
|
{
|
||||||
$dsn = "ibm:DRIVER={$config['driverName']};DATABASE={$config['database']};HOSTNAME={$config['host']};PORT={$config['port']};PROTOCOL=TCPIP;";
|
return sprintf('ibm:DRIVER=%s;DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;%s',
|
||||||
|
$config['driverName'],
|
||||||
return $dsn;
|
$config['database'],
|
||||||
|
$config['host'],
|
||||||
|
$config['port'],
|
||||||
|
$config['ssl'] ? 'SECURITY=SSL;' : '',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,36 @@ PDO::I5_TXN_NO_COMMIT
|
|||||||
return [
|
return [
|
||||||
|
|
||||||
'connections' => [
|
'connections' => [
|
||||||
|
'db2' => [
|
||||||
|
'driver' => 'pdo_ibm',
|
||||||
|
// or '{iSeries Access ODBC Driver}' '{IBM i Access ODBC Driver 64-bit}'
|
||||||
|
'host' => 'server',
|
||||||
|
'username' => '',
|
||||||
|
'password' => '',
|
||||||
|
'database' => 'WRKRDBDIRE entry',
|
||||||
|
'prefix' => '',
|
||||||
|
'schema' => 'default schema',
|
||||||
|
'port' => 50000,
|
||||||
|
'date_format' => 'Y-m-d H:i:s',
|
||||||
|
'ssl' => FALSE,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
'ibmi' => [
|
'drivers' => [
|
||||||
|
'pdo_ibm' => [
|
||||||
|
'driverName' => '{IBM DB2 ODBC DRIVER}',
|
||||||
|
'options' => [
|
||||||
|
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
||||||
|
PDO::ATTR_PERSISTENT => false
|
||||||
|
]
|
||||||
|
+ (defined('PDO::I5_ATTR_DBC_SYS_NAMING') ? [PDO::I5_ATTI5_ATTR_DBC_SYS_NAMINGR_COMMIT => false] : [])
|
||||||
|
+ (defined('PDO::I5_ATTR_COMMIT') ? [PDO::I5_ATTR_COMMIT => PDO::I5_TXN_NO_COMMIT] : [])
|
||||||
|
+ (defined('PDO::I5_ATTR_JOB_SORT') ? [PDO::I5_ATTR_JOB_SORT => false] : [])
|
||||||
|
+ (defined('PDO::I5_ATTR_DBC_LIBL') ? [PDO::I5_ATTR_DBC_LIBL => ''] : [])
|
||||||
|
+ (defined('PDO::I5_ATTR_DBC_CURLIB') ? [PDO::I5_ATTR_DBC_CURLIB => ''] : [])
|
||||||
|
],
|
||||||
|
|
||||||
|
'odbc_db2' => [
|
||||||
'driver' => 'db2_ibmi_odbc',
|
'driver' => 'db2_ibmi_odbc',
|
||||||
// or 'db2_ibmi_ibm' / 'db2_zos_odbc' / 'db2_expressc_odbc
|
// or 'db2_ibmi_ibm' / 'db2_zos_odbc' / 'db2_expressc_odbc
|
||||||
'driverName' => '{IBM i Access ODBC Driver}',
|
'driverName' => '{IBM i Access ODBC Driver}',
|
||||||
@ -150,7 +178,6 @@ return [
|
|||||||
+ (defined('PDO::I5_ATTR_DBC_LIBL') ? [PDO::I5_ATTR_DBC_LIBL => ''] : [])
|
+ (defined('PDO::I5_ATTR_DBC_LIBL') ? [PDO::I5_ATTR_DBC_LIBL => ''] : [])
|
||||||
+ (defined('PDO::I5_ATTR_DBC_CURLIB') ? [PDO::I5_ATTR_DBC_CURLIB => ''] : [])
|
+ (defined('PDO::I5_ATTR_DBC_CURLIB') ? [PDO::I5_ATTR_DBC_CURLIB => ''] : [])
|
||||||
],
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user