2021-07-09 01:38:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
declare(strict_types=1);
|
2021-07-09 01:38:30 +08:00
|
|
|
|
|
|
|
|
namespace ZM\MySQL;
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
use Doctrine\DBAL\Driver as DoctrineDriver;
|
2021-07-09 01:38:30 +08:00
|
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
|
|
|
|
use Doctrine\DBAL\Schema\MySqlSchemaManager;
|
|
|
|
|
use ZM\Config\ZMConfig;
|
|
|
|
|
use ZM\Console\Console;
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
class MySQLDriver implements DoctrineDriver
|
2021-07-09 01:38:30 +08:00
|
|
|
{
|
2022-03-15 18:05:33 +08:00
|
|
|
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
|
|
|
|
{
|
|
|
|
|
Console::debug('Requiring new connection');
|
2021-07-09 01:38:30 +08:00
|
|
|
return new MySQLConnection();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getDatabasePlatform(): MySqlPlatform
|
|
|
|
|
{
|
2021-07-09 01:38:30 +08:00
|
|
|
return new MySqlPlatform();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getSchemaManager($conn)
|
|
|
|
|
{
|
2021-07-09 01:38:30 +08:00
|
|
|
return new MySqlSchemaManager($conn);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getName()
|
|
|
|
|
{
|
2021-07-09 01:38:30 +08:00
|
|
|
return 'pdo_mysql_pool';
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getDatabase($conn)
|
|
|
|
|
{
|
|
|
|
|
$params = ZMConfig::get('global', 'mysql_config');
|
2021-07-09 01:38:30 +08:00
|
|
|
|
|
|
|
|
if (isset($params['dbname'])) {
|
|
|
|
|
return $params['dbname'];
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
return '';
|
2021-07-09 01:38:30 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
}
|