我希望我的脚本连接到数据库并在其中插入一个简单的 apikey。问题是脚本inst 连接到数据库。我在我的电脑上的 xampp 安装上运行这个脚本。
脚本:
<?php
$servername = "127.0.0.1";
$username = "[email protected]";
$password = "root";
$dbname = "apikey";
// Create a connection to the server
$conn = new mysqli ($servername, $username, $password, $dbname);
// Check the connection to the server
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO APIkey (APIkey)
VALUES ('John Doe')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " .$sql. "<br>" . $conn->error;
}
$conn->close();
?>
有没有人知道脚本可能有什么问题?
谢谢你的任何建议。
您不需要用户名上的主机
$username = "root";
是你所需要的全部
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句