gpt4 book ai didi

php - 如何将 html 连接到 Azure 数据库?

转载 作者:行者123 更新时间:2023-11-29 07:21:16 26 4
gpt4 key购买 nike

我正在尝试连接我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com