我使用這種語法而不是count(*),因爲它應該更快,但我不知道如何獲取產生的輸出MySQL&php PDO如何獲取:SELECT EXISTS(SELECT 1 FROM x WHERE y =:value)
$alreadyMember = $dataBase->prepare('SELECT EXISTS (SELECT 1
FROM TheCommunityReachLinkingTable
WHERE communityKey = :communityKey
AND userID = :userID)');
$alreadyMember->bindParam(':communityKey', $_POST['communityKey'], PDO::PARAM_STR);
$alreadyMember->bindParam(':userID', $_POST['userID'], PDO::PARAM_INT);
$alreadyMember->execute();
if($alreadyMember->fetch()) {do code here}
但它似乎沒有返回正確的東西,任何想法?
錯誤的SQL語法的返回值? :) –