diff --git a/Connection.php b/Connection.php index 7968255..d00ce79 100644 --- a/Connection.php +++ b/Connection.php @@ -48,7 +48,7 @@ class Connection extends Component public string $database = ''; - public int $timeout = 30; + public int $connect_timeout = 30; public int $waite_time = 3; @@ -344,10 +344,14 @@ class Connection extends Component PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => true, - PDO::ATTR_TIMEOUT => $this->timeout, + PDO::ATTR_TIMEOUT => $this->connect_timeout, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset ]); + $link = new PDO('mysql:dbname=' . $this->database . ';host=' . $this->cds, $this->username, $this->password, $options); + foreach ($this->attributes as $key => $attribute) { + $link->setAttribute($key, $attribute); + } return [$link, time()]; } diff --git a/DatabasesProviders.php b/DatabasesProviders.php index a5d504e..ddabb97 100644 --- a/DatabasesProviders.php +++ b/DatabasesProviders.php @@ -56,19 +56,19 @@ class DatabasesProviders extends Providers { $clientPool = $database['pool'] ?? ['min' => 1, 'max' => 5, 'tick' => 60]; return [ - 'id' => $database['id'], - 'cds' => $database['cds'], - 'class' => Connection::class, - 'username' => $database['username'], - 'password' => $database['password'], - 'tablePrefix' => $database['tablePrefix'], - 'database' => $database['database'], - 'timeout' => $database['timeout'] ?? 10, - 'idle_time' => $database['idle_time'] ?? 300, - 'waite_time' => $database['waite_time'] ?? 3, - 'pool' => $clientPool, - 'attributes' => $database['attributes'] ?? [], - 'charset' => $database['charset'] ?? 'utf8mb4' + 'id' => $database['id'], + 'cds' => $database['cds'], + 'class' => Connection::class, + 'username' => $database['username'], + 'password' => $database['password'], + 'tablePrefix' => $database['tablePrefix'], + 'database' => $database['database'], + 'connect_timeout' => $database['connect_timeout'] ?? 10, + 'idle_time' => $database['idle_time'] ?? 300, + 'waite_time' => $database['waite_time'] ?? 3, + 'pool' => $clientPool, + 'attributes' => $database['attributes'] ?? [], + 'charset' => $database['charset'] ?? 'utf8mb4' ]; }