Php dblib, Error: SQLSTATE [HY000] Unknown host name (severity 2)

I am using Mac OS OS 10.9. Freetds and unixODBC are already installed on my computer and added as a php extension, trying to connect to a remote MSSQL server. The following is a connection test:

<?php $dbh = new PDO('dblib:host=Hostname ;dbname=Dbname', 'user', 'pw'); if (!$dbh) { die('Something went wrong while connecting to MSSQL'); } ?> 

The error log file shows:

 [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] Unknown host machine name (severity 2) 

What could be the problem? It seems that my freetds and unixODBC are working fine if I use a terminal to connect to the same database as below:

 $ isql Hostname user pw +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> 

and

 $ tsql -S Hostname -U user Password: locale is "en_US.UTF-8" locale charset is "UTF-8" using default charset "UTF-8" 1> 

here is my freetds.conf

 [global] # TDS protocol version tds version = 8.0 [Hostname] host = IP port = 1433 tds version = 8.0 client charset = UTF-8 ##needed on MAC OS X dump file = /tmp/freetds.log 

and my odbc.ini

 [Hostname] #Driver=/usr/local/lib/libtdsodbc.so Driver = /usr/local/Cellar/freetds/0.91_2/lib/libtdsodbc.so Trace=No Server=IP Port=1433 TDS_Version=8.0 client charset = UTF-8 

my phpinfo () shows that an additional extension has been added, in the PDO section there is dblib, and in the pdo_dblib section there is a driver with frists enabled.

So what is the problem? Any idea what should I do? Any help would be greatly appreciated.

here is my odbcinst.ini:

 [freetdS] Description = v0.63 with protocol v8.0 Driver = /usr/local/Cellar/freetds/0.91_2/lib/libtdsodbc.so 
+7
php sql-server pdo macos freetds
source share
2 answers

I really solved this issue by deleting both mssql.so, pdo_dblib.so in the php extension folder, reload php5.4, phpize and create both .so files again and return them. Then it works.

It seems that the olde pdo_dblib.so file that I made was pointing to another freetds.conf somewhere else.

+2
source share

Since it is impossible to debug it through a proxy without information about real files, and you decided to protect ip addresses and host names with dummy text. I am moving on to the PHP code. The host name must be an FQDN or IP address. Not the text of the place owner from ini files

 <?php $dbh = new PDO('dblib:host=[ ip address || example.com || localhost] ;dbname=Dbname', 'user', 'pw'); if (!$dbh) { die('Something went wrong while connecting to MSSQL'); } ?> 
0
source share

All Articles