我正在编写这个 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 connectionif ($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)我哪里错了?
1 回答
精慕HU
TA贡献1845条经验 获得超8个赞
查询中有语法错误。
最后缺少封闭括号
字符串登录被给出了两次
请参阅下面的更正版本。
$sql = "INSERT INTO events (`ID`, `eventName`, `timeStamp`, `dateModified`) VALUES ('1', 'Login', '12/12/2019', '$dateModified')";
拒绝访问意味着,用户dev没有插入权限。
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报
0/150
提交
取消