SQL不会在数据库中创建任何内容 [英] SQL dosen't create anything in database

查看:121
本文介绍了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)");

编辑:在您的评论中,您向我们展示了用户,并且列 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);

这篇关于SQL不会在数据库中创建任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆