SQLSTATE [01002] Failed to connect to the adaptive server (grade 9)

I have the following script to connect to my Microsoft Azure server.

<?php

try {
    $hostname = "secrets.database.windows.net";
    $dbname = "secrets";
    $username = "secrets";
    $pw = "secrets";
    $dbh = new PDO ("dblib:host=$hostname;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
}

echo "Passed!";

The script above is on my old server, but gives me the following error message when starting from a new server.

SQLSTATE[01002] Adaptive Server connection failed (severity 9)

Setting up my new PHP server:

sudo apt-get install -y php5.6-fpm php5.6-ldap php5.6-curl php5.6-cli   php5.6-mcrypt php5.6-intl php5.6-json php5.6-pdo-dblib php5.6-mysqlnd php5.6-memcached php5.6-mbstring php5.6-imap php5.6-xml php5.6-sybase

My checks so far:

1) Both have the same public IP address.

2) Both have the same PHP PDO / ODBC setting.

$ php -i | grep PDO
DO
PDO support => enabled
PDO drivers => dblib, mysql, odbc
PDO Driver for FreeTDS/Sybase DB-lib => enabled
PDO Driver for MySQL => enabled
PDO_ODBC
PDO Driver for ODBC (unixODBC) => enabled

3) I can ping my server using telnet from both servers using:

telnet secrets.database.windows.net 1433

Any suggestions would be appreciated.

+5
source share
4 answers

After some further searching, I came across this answer.

Connect PHP to MSSQL via PDO ODBC

, /etc/freetds/freetds.conf

:

TDS .

tds version = 8.0

mssql .

[mssql]
host =
Port = 1433
tds version = 8.0
+8

, ​​ FreeTDS 8.0 PHP-:

<?php

try {
    $hostname = "secrets.database.windows.net";
    $dbname = "secrets";
    $username = "secrets";
    $pw = "secrets";
    $dbh = new PDO ("dblib:version=8.0;charset=UTF-8;host={$hostname};dbname={$dbname}", $username, $pwd);
} catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
}

echo "Passed!";
+2

$dbname, .

+1

.

0

All Articles