PHP error connecting to MS SQL database using PDO_DBLIB

后端 未结 2 1882
夕颜
夕颜 2020-12-11 02:34

I am attempting to use PHP\'s PDO_DBLIB driver to connect to a remote database and am having some issues.

The database is connectable via the same environment using

相关标签:
2条回答
  • 2020-12-11 03:27

    Write port into freetds.conf directly for this host:

    [RemoteServer]
        host = RemoteServer
        port = 1433
    

    And leave php-code us is:

    $conn = new PDO('dblib:dbname=TestDB;host=RemoteServer;charset=utf8', 'my_user', 'my_pass');
    
    0 讨论(0)
  • 2020-12-11 03:29

    Turns out that it was a much simpler issue than I thought. For whatever reason, the development server was not using Port 1433 as the default port in the connection and was instead using Port 4000.

    I discovered this by enabling the logs in the freetds.conf file and monitoring them as I was making the request.

    Also, something to note: The DBLIB extension uses a colon (:) as a separator between the host and the port instead of the comma. Unfortunately, the error that you receive when you use a comma isn't very descriptive, so hopefully someone benefits from this discovery.

    0 讨论(0)
提交回复
热议问题