Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: SQLSRV with specified port over network #6032

Closed
alfisahr opened this issue May 26, 2022 · 2 comments · Fixed by #6036
Closed

Bug: SQLSRV with specified port over network #6032

alfisahr opened this issue May 26, 2022 · 2 comments · Fixed by #6036
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer

Comments

@alfisahr
Copy link

alfisahr commented May 26, 2022

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.

@alfisahr alfisahr added the bug Verified issues on the current code behavior or pull requests that will fix them label May 26, 2022
@kenjis kenjis added the database Issues or pull requests that affect the database layer label May 27, 2022
@kenjis
Copy link
Member

kenjis commented May 27, 2022

This bug was fixed in the develop branch,
and it will be included in v4.2.0.

Thank you for reporting.

@iRedds
Copy link
Collaborator

iRedds commented Jun 20, 2022

@alfisahr Can you tell me if this fix solved the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants