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]
and my odbc.ini
[Hostname]
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
php sql-server pdo macos freetds
na83
source share