Skip to content

Commit

Permalink
Merge pull request #8986 from kenjis/fix-OCI8-connect
Browse files Browse the repository at this point in the history
fix: [OCI8] if conditions to build DSN
  • Loading branch information
kenjis authored Jun 24, 2024
2 parents 9d02066 + 99346b4 commit ab64aeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@
$ignoreErrors[] = [
// identifier: empty.notAllowed
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 5,
'count' => 2,
'path' => __DIR__ . '/system/Database/OCI8/Connection.php',
];
$ignoreErrors[] = [
Expand Down
10 changes: 7 additions & 3 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class Connection extends BaseConnection
*/
private function isValidDSN(): bool
{
if ($this->DSN === null || $this->DSN === '') {
return false;
}

foreach ($this->validDSNs as $regexp) {
if (preg_match($regexp, $this->DSN)) {
return true;
Expand All @@ -120,13 +124,13 @@ private function isValidDSN(): bool
*/
public function connect(bool $persistent = false)
{
if (empty($this->DSN) && ! $this->isValidDSN()) {
if (! $this->isValidDSN()) {
$this->buildDSN();
}

$func = $persistent ? 'oci_pconnect' : 'oci_connect';

return empty($this->charset)
return ($this->charset === '')
? $func($this->username, $this->password, $this->DSN)
: $func($this->username, $this->password, $this->DSN, $this->charset);
}
Expand Down Expand Up @@ -632,7 +636,7 @@ protected function buildDSN()
}

$isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':');
$easyConnectablePort = ! empty($this->port) && ctype_digit($this->port) ? ':' . $this->port : '';
$easyConnectablePort = ($this->port !== '') && ctype_digit((string) $this->port) ? ':' . $this->port : '';
$easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : '';

if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) {
Expand Down

0 comments on commit ab64aeb

Please sign in to comment.