提问人:Hamzah Faleel 提问时间:11/3/2023 更新时间:11/3/2023 访问量:26
将我的 Google Cloud SQL 数据库连接到我托管的 PHP 应用程序
connecting my google cloud sql database, to my hosted php app
问:
我正在运行一个项目,我的 PHP 应用程序在其中发出 HTTP 请求,然后它在我的 Google Cloud SQL 数据库中更新该值。我尝试使用公共 IP 进行连接,但遇到同样的错误。
<?php
if(isset($_GET["temperature"])) {
$temperature = $_GET["temperature"]; // get temperature value from HTTP GET
$servername = "34.69.43.41";
$username = "XXXXX";
$password = "XXXX";
$database_name = "LeafLink";
// Create MySQL connection fom PHP to MySQL server
$connection = new mysqli($servername, $username, $password, $database_name);
// Check connection
if ($connection->connect_error) {
die("MySQL connection failed: " . $connection->connect_error);
}
$sql = "INSERT INTO incoming_data (raw_data) VALUES ($temperature)";
if ($connection->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . " => " . $connection->error;
}
$connection->close();
} else {
echo "temperature is not set in the HTTP request";
}
?>
这是 PHP 文件。提交请求时,我收到此错误。我是使用 MySQL 和 PHP 的新手,因此非常感谢任何帮助
答: 暂无答案
评论