-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
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.