若是有出現
SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server (severity 16)
(dbutil.c:86):msgno 40508: "USE statement is not supported to switch between databases. Use a new connection to connect to a different Database."
那原因在於Azure SQL連了之後並不能改選資料庫
解決方法一開始就指定資料庫,PDO連線方式若不能改,請將PHP從5.3升級到5.4.
詳情參考http://stackoverflow.com/questions/20057294/dblib-pdo-driver-keeps-failing-when-trying-to-connect-query-microsoft-azure-sql
還有一種可能性是安裝freetds之後後,並未設定連線的版本號,或者版本號沒對應到。
yum install freetds
這情況下用PDO連線改成如下:
$dsn = "dblib:version=8.0;charset=UTF-8;host=<*.database.windows.net>;dbname=<dbname>";
$user = '';
$password = '';
try {
$db = new PDO($dsn, $user, $password);
} catch (PDOException $e){
echo $e->getMessage();
}