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

如何从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.

    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏