我试图查看$ steamId中存储的值是否已经存在于表中,但它无法正常工作。我做错了什么。
Account_info表
+------------+---------+----------+-----+
| Steam_id | Partner | Token | RID |
+------------+---------+----------+-----+
| Steamid222 | Part222 | token222 | 1 |
+------------+---------+----------+-----+
$stmt = $conn->prepare("SELECT Steam_id from Account_info WHERE Steam_id = ':id'");
$stmt->bindParam(":id", '$steamId');
$stmt->execute();
if($stmt->rowCount() > 0)
{
//user exists
}
else
{
//user doesn't exist
}
答案 0 :(得分:1)
您将确切的字符串'$steamId'
绑定到ID,以便搜索ID为'$steamId'
的用户。
$stmt->bindParam(":id", $steamId, PDO::PARAM_STR);
您也可以从select语句中删除引号。
$stmt = $conn->prepare("SELECT Steam_id from Account_info WHERE Steam_id = :id");