dtwye28880 2016-03-15 09:20
浏览 78

如何从Linux服务器连接Azure中的sql Server与Php?

I have been using azure mobile services for my android application. Then I want to access my database datas with my Localhost and Remote server using Php.

I tried the codes that is given by Azure docs below.

$conn = new PDO ( "sqlsrv:server = tcp:MYSERVERNAME.database.windows.net,1433; Database = MY_DATABASE_NAME", "MY_USER_NAME", "MY_PASSWORD" );
try {
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

} catch ( PDOException $e ) {
    print( "Error connecting to SQL Server." );
    die( print_r( $e ) );

};

When The code is runned on Localhost or Remote server, that is Linux server, I get error below

enter image description here

EDIT

I thought it is about Azure firewall rules and I added my IP number in Azure Firewall rules for Server

When I tried to connect to Server via SQLPro I could connect successfuly and I started to query. But I can not to connect via Localhost with my Php codes.

  • 写回答

3条回答 默认 最新

  • dongyi6269 2016-03-16 05:18
    关注

    The function you used PDO sqlsrv:server requires SQLSRV extension like php_pdo_sqlsrv_53_nts.dll, but which is only compatible with PHP running on Windows.

    To connect to SQL server in PHP in Unix, you can use ODBC extension and Microsoft's SQL Server ODBC Driver for Linux.

    You can refer to http://php.net/manual/en/ref.pdo-sqlsrv.php for details.

    评论

报告相同问题?