sql server - PDO_ODBC and unixODBC cannot connect MSSQL with non-default port -


i have connect 2 mssql servers on php/linux environment. decide use unixodbc , pdo_odbc.

  • mssql on server1: 10.10.10.5:1433

  • mssql on server2: 10.10.10.8:14233 (non-default port number)

i think there port problem of pdo_odbc or unixodbc. tried code below.

this code works fine. connected successfully.

$db = new pdo('odbc:driver=sql server native client 11.0; server=10.10.10.5; port=1433; database=dbname; uid=uid; pwd=pwd'); 

this code didn't work. connect failed.

$db = new pdo('odbc:driver=sql server native client 11.0; server=10.10.10.8; port=14233; database=dbname; uid=uid; pwd=pwd'); 

strangely, code works fine wrong value. :(

$db = new pdo('odbc:driver=sql server native client 11.0; server=10.10.10.5; port=14233; database=dbname; uid=uid; pwd=pwd'); 

i concluded ignore port setting on dsn of pdo.

i tried other setting using /etc/odbc.ini

[odbc-erp] driver=sql server native client 11.0 description=mssql trace=yes server=10.10.10.8 port=14233 database=dbname 

and, code didn't make connection.

$dbh = new pdo('odbc:odbc-erp', $uid, $pwd); 

error message:

db error: sqlstate[hyt00] sqlconnect: 0 [unixodbc][microsoft][sql server native client 11.0]login timeout expired in /home/user/public_html/test/testodbc.php on line 40 

and, code works fine.

[odbc-mes] driver=sql server native client 11.0 description=mssql trace=yes server=10.10.10.5 port=14233              // wrong value (10.10.10.5 server port 1433.) database=dbname 

and, code didn't make connection.

$dbh = new pdo('odbc:odbc-mes', $uid, $pwd); 

the ports opened. tcpdump show connection use use ms-sql-s (1433). sqlcmd works fine.

# sqlcmd -u uid -p pwd -s 10.10.10.8,14233 -d oes 1> select @@version 2> go  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ microsoft sql server 2008 r2 (sp2) - 10.50.4033.0 (x64)      jul  9 2014 16:04:25      copyright (c) microsoft corporation     enterprise edition (64-bit) on windows nt 6.1 <x64> (build 7601: service pack 1)   (1 rows affected) 1> 

i wonder i'm missing. or there other way connect mssql?

  • centos 6.6
  • php 5.5.19
  • sqlncli-11.0.1790.0

-

# rpm -qa php-5.5.19-2.el6.remi.x86_64 php-mssql-5.5.19-2.el6.remi.x86_64 php-odbc-5.5.19-2.el6.remi.x86_64 php-pdo-5.5.19-2.el6.remi.x86_64  # sqlcmd microsoft (r) sql server command line tool version 11.0.1790.0 linux copyright (c) microsoft corporation.  rights reserved.  # cat /etc/sysconfig/selinux  selinux=disabled selinuxtype=targeted  

the driver doesn't support port keyword. per documentation, need append port after server name in dsn:

server=10.10.10.5,14233 

the documentation lists keywords are supported.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -