doumou3883 2016-11-02 02:28
浏览 45

PHP连接到Azure-SQL数据库

In the below code, I try to connect to an azure-sql database with PHP, and in the first part of the if, I write out if the connection failed, which I don't receive. In the next else, I write out if the connection passed, which I get the message on ("Connection succeeded"). This appears to connect correctly; however, I do get an output of 0 even though it clearly hits this part of the else. I can't tell from research if 0 means success, but if it the connection failed, wouldn't it hit the first part of the if?

The problem is that this code isn't outputting the array column added to the string, so it appears that while it's registering as succeeding, it's actually failing, or something else is wrong, like the syntax.

<?php 

    /// Test variable
    $writeOutResult = "Result:  ";

    /// VARIABLES NOT INCLUDED

    /// Connect
    $connInfo = array("Database"=>$azureDB
            , "UID"=>$azureUser
            , "PWD"=>$azurePass
            , "MultipleActiveResultSets"=>true
        );
    $conn = sqlsrv_connect($azureServer,$connInfo);

    /// Test connection
    if($conn === false)
    {
        //FatalError("Server unavailable.");
        $writeOutResult = "Connection failed.";
    }
    else
    {       
        echo "Connection succeeded";
        $get = sqlsrv_query($conn,$query);

        while ($row = sqlsrv_fetch_array($get, SQLSRV_FETCH_ASSOC))
        {
            $writeOutResult += $row["Column"];
        }
    }
?>
<html>
<head><title></title></head>
<body>
<p>Output:</p>
<?php 
    echo $writeOutResult;
?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dpv46227 2016-11-18 10:33
    关注

    It seems that there is no obvious error on PHP. I tested on my side and which worked fine.

    It could be the case of following causes, you can check one by one.

    • Please check the SQL query stmt, whether it's correct, you can query it in SSMS for verification.

    • Check the value and data type. Whether it can be plus directly.

    Any further concern, please feel free to let me know.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测