我正在尝试连接我的azure sql storeage和html,以显示我拥有的一切。但是我遇到了一些麻烦。我研究了W3School和其他资源,但我仍然不知道怎么了?
所以我使用记事本 并将其保存为html
,然后使用php
建立连接
这是到目前为止我的记事本 中的代码:
<?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("Connection failed: " . $conn->connect_error);
我不知道我在哪里做错了。如果可以的话,请帮助我,谢谢
我不是100%确定的,因为我不是php dev,但是Microsoft在其Azure文档上具有以下内容(此处(:
<?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
$host = '****.mysql.database.azure.com';
$username = '****@mysql****';
$password = '****';
$db_name = '*****';
//Establishes the connection
$conn = mysqli_init();
printf("hello")
mysqli_real_connect($conn, $host, $username, $password, $db_name, 3306);
if (mysqli_connect_errno($conn)) {
printf("sory");
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
// Run the create table query
if (mysqli_query($conn, '
select * from table1;
')) {
printf("Table createdn");
}
//Close the connection
mysqli_close($conn);
?>
它返回一个空白页,我觉得它只是如何跳过我的所有PHP代码