我希望我的脚本连接到数据库并在其中插入一个简单的apikey。问题是脚本inst连接到数据库。我在我的电脑上的xampp安装上运行这个脚本。
脚本:
<?php
$servername = "127.0.0.1";
$username = "root@127.0.0.1";
$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();
?>
有没有人知道脚本可能出现什么问题?
感谢您的任何建议。
答案 0 :(得分:0)
您不需要用户名
上的主机$username = "root";
你需要的只是