SQL不会在数据库中创建任何内容
这是我的代码,但是当我在用户下输入数据库时,什么都没有创建。
它已经工作过。
This is my code, but when I enter my database under users, nothing was created. It has worked before.
这是我的数据库信息
Here is my database informations
$odb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
if(!$odb){ die('Connection Failed!'); }
?>
这就是我想要创建用户的地方。
And this is where i would like to create a user.
$steamid = $steamprofile['steamid'];
/*Check possible existing data*/
$SQLCheckLoginQuery = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `steamid` = :SteamID");
$SQLCheckLoginQuery -> execute(array(':SteamID' => $steamid));
$countUsers = $SQLCheckLoginQuery -> fetchColumn(0);
if($countUsers <= 0){
$SQLInsertQuery = $odb -> prepare("INSERT INTO `users` (steamid) VALUES :SteamID");
$SQLInsertQuery -> execute(array(':SteamID' => $steamid));
}
?>
你的mysql查询似乎有错误,您的VALUES应位于括号之间:
You seems to have an error in your mysql query, your VALUES should be between brackets:
$SQLInsertQuery = $odb -> prepare("INSERT INTO `users` (steamid) VALUES (:SteamID)");
编辑:在您的评论中,您向我们展示了用户$的结构c $ c>,并且列
avatar
似乎是强制性的。因此,您应该在插入查询中设置默认值或添加头像
On your comment you show us the structure of users
, and the column avatar
seems to be mandatory. So you should make a default value or add the avatar in your insert query
$SQLInsertQuery = $odb -> prepare("INSERT INTO `users` (steamid, avatar) VALUES (:SteamID, :avatar)");
另外,您可以激活日志以查看是否抛出了一些异常
Also, you can activate log in order to see if some exception are throwed
$odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);