PHP与Azure-SQL数据库的连接 [英] PHP Connection To Azure-SQL Database

查看:121
本文介绍了PHP与Azure-SQL数据库的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我尝试使用PHP连接到azure-sql数据库,并且在if的第一部分中,我写出了连接失败的消息,但我没有收到.在接下来的其他步骤中,我写出连接是否通过的信息,然后将其显示在消息中(连接成功").这似乎正确连接;但是,我确实得到了 0 的输出,即使它显然触及了else的这一部分.从研究中我无法确定0是否意味着成功,但是如果连接失败,它将不会碰到if的第一部分?

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>

推荐答案

似乎在PHP上没有明显的错误.我站在一边测试,效果很好.

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.

  • 请检查SQL查询stmt,是否正确,可以在SSMS中查询以进行验证.

  • 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.

这篇关于PHP与Azure-SQL数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆