猿问

PHP 不会使用 mssql_connect 连接到 Azure SQL DB

我需要从共享 cPanel 主机上的外部 PHP 应用程序连接到 Azure SQL DB。


我的主机启用了 mssql_connect 但不会在共享环境中启用 MS 推荐的 sqlsrv_connect。


我已将 Azure 门户中的网络服务器 IP 列入白名单,并将 cPanel 中的 DB 地址列入白名单。


测试脚本似乎尝试连接,但无法连接。没有提供错误信息:http : //app.hivve.com.au/api/


PHP是:


$db_server = "cjweb.database.windows.net:1433"; // update me

$db_username = "username";

$db_password = "password";


$conn = mssql_connect($db_server, $db_username, $db_password);


print_r(mssql_get_last_message());

有没有其他人走过这条路?我的主人不会再提供帮助,所以我卡住了。


江户川乱折腾
浏览 174回答 2
2回答

海绵宝宝撒

我在 Azure SQL 文档快速入门中发现的内容:使用 PHP 查询可能丢失了“UID”参数的 Azure SQL 数据库。<?php&nbsp; &nbsp; $serverName = "your_server.database.windows.net"; // update me&nbsp; &nbsp; $connectionOptions = array(&nbsp; &nbsp; &nbsp; &nbsp; "Database" => "your_database", // update me&nbsp; &nbsp; &nbsp; &nbsp; "Uid" => "your_username", // update me&nbsp; &nbsp; &nbsp; &nbsp; "PWD" => "your_password" // update me&nbsp; &nbsp; );&nbsp; &nbsp; //Establishes the connection&nbsp; &nbsp; $conn = sqlsrv_connect($serverName, $connectionOptions);?>您可以先测试 Alberto Morillo 的代码。希望这可以帮助。

达令说

您可以尝试如下所示连接吗?请看用户名。在 ~/.freetds.conf 上添加 [aftermath]:[aftermath]&nbsp; &nbsp; database = mydatabase&nbsp; &nbsp; host = cjweb.database.windows.net&nbsp; &nbsp; port = 1433&nbsp; &nbsp; tds version = 8.0$myServer = "aftermath"$myUser = cjweb@cjweb$myPass = your_password$dbhandle = mssql_connect($myServer, $myUser, $myPass)&nbsp; or die("Couldn't connect to SQL Server on $myServer");
随时随地看视频慕课网APP
我要回答