Welcome Guest, Not a member yet? Register   Sign In
SQL Server with custom port
#1

Using SQL Server with default port (1433) is work well. But when we use custom port, the .env or config field database.nls.port = 5000, its not given any effect, didn't work.
So, I tried to change connection syntax inside Connection.php core class CodeIgniter\Database\SQLSRV\Connection.

My questions:
1. Is this a bug ? because field database.nls.port (.env) or $default['port'] (config) doesn't work if we use custom port (especially for SQLSRV)
2. How do we override this Connection class. (Yes, I already read in the doc, create our own class, and register in autoload, but it didn't work).

Thank you.
Reply
#2

I found this documentation at Microsoft:
https://docs.microsoft.com/en-us/sql/con...rver-ver16

It looks like you need to add the port to the hostname.
$serverName = "myServer, 1521";  
sqlsrv_connect( $serverName );      

in system/Database/SQLSRV/Connection.php at Line 123
PHP Code:
sqlsrv_configure('WarningsReturnAsErrors'0);
$this->connID sqlsrv_connect($this->hostname$connection); 

to test it change it to:
PHP Code:
sqlsrv_configure('WarningsReturnAsErrors'0);
$port = empty($this->port) ? '' ', '.$this->port;
$this->connID sqlsrv_connect($this->hostname.$port$connection); 

if that works, it's a bug. I can't test it right now because I don't have access to an sql server
Reply
#3

(05-23-2022, 08:19 PM)ilyani Wrote: Using SQL Server with default port (1433) is work well. But when we use custom port, the .env or config field database.nls.port = 5000, its not given any effect, didn't work.
So, I tried to change connection syntax inside Connection.php core class CodeIgniter\Database\SQLSRV\Connection.

My questions:
1. Is this a bug ? because field database.nls.port (.env) or $default['port'] (config) doesn't work if we use custom port (especially for SQLSRV)
2. How do we override this Connection class. (Yes, I already read in the doc, create our own class, and register in autoload, but it didn't work).

Thank you.

Here file I modified, connect() method Connection.php for SQLSRV under /vendor/codeigniter4/framework/system/Database/SQLSRV/Connection.php 

from this

PHP Code:
...
$this->connID sqlsrv_connect($this->hostname$connection);
... 

to this

PHP Code:
...
$this->connID sqlsrv_connect($this->hostname ', ' $this->port$connection);
... 

How to override this Connection class, without direct modify like this?

Thanks
Reply
#4

1. This is a bug.
2. If I'm not mistaken, you can't replace just the connection class. You need to fully implement the driver.
Reply
#5

See
a simple way to extend the Database classes
https://forum.codeigniter.com/thread-782...#pid383813
Reply
#6

Can you help try to specify the port in hostname 'hostname' => 'host, port',
I don't know if this will work.
Reply
#7

This bug was fixed in the `develop` branch.
https://github.com/codeigniter4/CodeIgniter4/pull/6036

And it would be included in v4.2.0.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB