【发布时间】:2016-05-07 05:06:47
【问题描述】:
我的代码有问题。
我想向我的数据库中添加的不仅仅是我的:SteamID。
目前,每次您进入我的网站时,此功能/PDO 都会运行。 工作代码:
/*Check possible existing data*/
$odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$SQLCheckLoginQuery = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `steamid` = :SteamID");
$SQLCheckLoginQuery -> execute(array(':SteamID' => $steamid));
// $SQLCheckLoginQuery -> execute(array(':avatar' => $avatarid));
$countUsers = $SQLCheckLoginQuery -> fetchColumn(0);
if($countUsers <= 0){
$SQLInsertQuery = $odb -> prepare("INSERT INTO `users` (steamid) VALUES (:SteamID)");
$SQLInsertQuery -> execute(array(':SteamID' => $steamid));
这也是我想添加到我的数据库中的内容。
**// I want this stuff to be updated every time it runs this section**
$SQLInsertQuery -> execute(array(':avatar' => $avatarid));
$SQLCheckLoginQuery -> execute(array(':steamName' => $steamname));
}
?>
问题是它不允许我将:avatar and :steamName 添加到我的数据库中。
【问题讨论】:
-
你有什么问题?
-
它不会将新内容添加到数据库中。
-
为什么不将它添加到您添加 :SteamID 的同一个执行中?
-
所以将此字段添加到您的查询中。你知道怎么写查询吗?
-
execute()函数实际执行查询,尝试使用bindParam(),然后在绑定两个参数后使用execute()。
标签: php html mysql database pdo