Skip to content

Commit

Permalink
tweak: use constants from base class
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jul 17, 2024
1 parent 3f26fc2 commit fec1989
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Connection/Driver.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace Gt\Database\Connection;

use PDO;

class Driver {
/** @noinspection PhpUnused */
const AVAILABLE_DRIVERS = [
"cubrid",
"dblib", // Sybase databases
Expand All @@ -18,10 +21,8 @@ class Driver {
"4D",
];

/** @var SettingsInterface */
protected $settings;
/** @var Connection */
protected $connection;
protected SettingsInterface $settings;
protected Connection $connection;

public function __construct(SettingsInterface $settings) {
$this->settings = $settings;
Expand All @@ -42,15 +43,15 @@ public function getConnection():Connection {

protected function connect():void {
$options = [
Connection::ATTR_ERRMODE => Connection::ERRMODE_EXCEPTION,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];

if($this->settings->getDriver() === Settings::DRIVER_MYSQL) {
$options[Connection::MYSQL_ATTR_INIT_COMMAND]
$options[PDO::MYSQL_ATTR_INIT_COMMAND]
= "SET SESSION collation_connection='"
. $this->settings->getCollation()
. "'";
$options[Connection::MYSQL_ATTR_LOCAL_INFILE] = true;
$options[PDO::MYSQL_ATTR_LOCAL_INFILE] = true;
}

$this->connection = new Connection(
Expand Down
2 changes: 2 additions & 0 deletions test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
var_dump(PDO::getAvailableDrivers());

0 comments on commit fec1989

Please sign in to comment.