作者:傅雪莱_ | 来源:互联网 | 2023-06-24 16:09
我正在编写此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','12/12/2019',".$dateModified;
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
?>
我收到此错误:
2002 : Connection timed out
有趣的是,如果我将其包装在一个函数中并尝试相同的操作,则会出现此错误:
1045 : access denied for user ''@'localhost' (using password: YES)
我要去哪里错了?
查询中存在语法错误。
请参阅下面的更正版本。
$sql = "INSERT INTO events (`ID`,`eventName`,`timeStamp`,`dateModified`)
VALUES ('1','Login','12/12/2019','$dateModified')";
拒绝访问意味着用户 dev 没有插入特权。