Skip to content

Bug: SQLSRV with specified port over network #6032

@alfisahr

Description

@alfisahr

PHP Version

7.4

CodeIgniter4 Version

4.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

SQL Server 2019

What happened?

Database doesn't connect using non default SQL Server port, which is 1433 is default port. Especially when we connect to other machine (over network) instead of our local. Configuration database.default.port = (in .env) or $config['default']['port'] = (in config) didn't give any effect, not worked.

If we use local db, whatever port that use in the server db, the connection still work. But the problem comes if we connect other machine in the network.

In the Connection.php class under /vendor/codeigniter4/framework/system/Database/SQLSRV there are

...
$this->connID = sqlsrv_connect($this->hostname, $connection);
...

then I modified like this

...
$this->connID = sqlsrv_connect($this->hostname . ', ' . $this->port, $connection);
...

it solved the problem

Steps to Reproduce

  • Use db from other machine that have custom port, instead of default port.
  • You can specify port db in the configuration following that db server custom port

Expected Output

Connection to db works as same like using default port

Anything else?

I tried to modify this class under /vendor/codeigniter4/framework/system/Database/SQLSRV/Connection.php

from this

...
$this->connID = sqlsrv_connect($this->hostname, $connection);
...

to this

...
$this->connID = sqlsrv_connect($this->hostname . ', ' . $this->port, $connection);
...

How to override this class in our library, without directly modify like that.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix themdatabaseIssues or pull requests that affect the database layer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions