我正在编写这个 PHP 程序,它将一条记录插入一个名为事件的表中。PHP代码是:
<?php
$servername = "example.com";
$username = "dev";
$password = "some password";
$dbname = "mydb";
$dateModified = gmdate("Y-m-d h:i:s a");
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die($conn -> connect_errno. " : ".$conn -> connect_error);
}
$sql = "INSERT INTO events (ID, eventName, timeStamp, dateModified)
VALUES ('1', 'Login', 'Login', '12/12/2019',".$dateModified;
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
我收到此错误:
2002 : Connection timed out
有趣的是,如果我将它包装在一个函数中并尝试相同的方法,则会出现此错误:
1045 : Access denied for user ''@'localhost' (using password: YES)
我哪里错了?
精慕HU