PHP脚本无法连接到sql数据库
我希望我的脚本连接到数据库,并在其中插入一个简单的apikey。问题是脚本无法连接到数据库。我在电脑上的xampp安装上运行此脚本 脚本:PHP脚本无法连接到sql数据库,php,mysql,sql,Php,Mysql,Sql,我希望我的脚本连接到数据库,并在其中插入一个简单的apikey。问题是脚本无法连接到数据库。我在电脑上的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
<?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();
?>
用户名上不需要主机
$username = "root";
这就是你所需要的