作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试连接我的 Azure Sql 存储和 html 以显示我拥有的所有内容。但我遇到了一些麻烦。我研究了 w3school 和其他资源,但我仍然不知道哪里出了问题?
所以我使用 Notepad++ 并将其保存为 html
并使用 php
建立连接
到目前为止,这是我 Notepad++ +中的代码:
<?php
$servername = "servername*****.mysql.database.azure.com";
$username = "loginfor****n@mysql***";
$password = "*****";
$db = "db";
// Create connection
$conn = new mysqli($servername, $username, $password. $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
这就是我得到的connect_error) { die("连接失败:". $conn->connect_error);
我不知道我哪里错了。如果可以,请帮助我,谢谢
最佳答案
我不能 100% 确定,因为我不是 PHP 开发人员,但 Microsoft 在他们的 Azure 文档 ( here ) 中有以下内容:
<?php
$serverName = "your_server.database.windows.net"; // update me
$connectionOptions = array(
"Database" => "your_database", // update me
"Uid" => "your_username", // update me
"PWD" => "your_password" // update me
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
$tsql= "SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
FROM [SalesLT].[ProductCategory] pc
JOIN [SalesLT].[Product] p
ON pc.productcategoryid = p.productcategoryid";
$getResults= sqlsrv_query($conn, $tsql);
echo ("Reading data from table" . PHP_EOL);
if ($getResults == FALSE)
echo (sqlsrv_errors());
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
echo ($row['CategoryName'] . " " . $row['ProductName'] . PHP_EOL);
}
sqlsrv_free_stmt($getResults);
?>
我的猜测是您的 PHP 格式不正确,您得到的是代码渲染而不是它实际正确执行 - 请务必阅读文档。
关于php - 如何将 html 连接到 Azure 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56235479/
我是一名优秀的程序员,十分优秀!