gpt4 book ai didi

php - 使用 PHP 将网站连接到 Azure SQL 数据库

转载 作者:行者123 更新时间:2023-12-03 03:53:09 24 4
gpt4 key购买 nike

我现在一直在努力让我的网站连接到 Azure SQL 数据库。在我的个人计算机上,我使用驱动程序设置了 XAMP(我认为)。这是代码:

            <tr>
<th scope="col">Link</th>
<th scope="col">Assigned to</th>
<th scope="col">Category</th>
</tr>
<?php

// SQL Server Extension Sample Code:
$connectionInfo = array("UID" => "*****", "pwd" => "*******", "Database" => "SAND", "LoginTimeout" => 30, "Encrypt" => 1, "TrustServerCertificate" => 0);
$serverName = "tcp:myfsusqlserver.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);


$selected = mysql_select_db('SAND', $conn); //select db
$viewQuery = "select * from dbo.LINK join dbo.CUSTOMER";
$execute = mysql_query($viewQuery);
while($dataRows=mysql_fetch_array($execute))
{
$url = $dataRows['URL'];
$email = $dataRows['CUSTOMER_ID'];
$cat = $dataRows['CAT_ID'];

}?>
<tr>
<td><?php echo $url; ?></td>
<td><?php echo $email; ?></td>
<td><?php echo $cat; ?></td>

</tr>
</table>
?php>

如果有人能帮助我解决我的问题,我将不胜感激。

快速更新:

它给了我这个错误:

Fatal error: Uncaught Error: Call to undefined functionsqlsrv_connect() inC:\xampp\htdocs\BUILDERSEXCHANGEWEBSITE\index.php:67 Stack trace: #0{main} thrown in C:\xampp\htdocs\BUILDERSEXCHANGEWEBSITE\index.php online 67

最佳答案

您的代码不适合 Azure SQL 数据库。

使用此示例 connect to Azure SQL DB and query data :

<?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 将网站连接到 Azure SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65729031/

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