使用PDO查询多个表的最有效方法是什么?

时间:2014-03-09 03:46:50

标签: php mysql pdo

所以我终于抽出时间开始学习PDO了。我现在正在运行这样的查询,只是想知道是否有更有效的方法来构建这些查询:

    //Do the database queries
    try{
        $checkInvites = $db->prepare("SELECT id FROM invites WHERE email = '$email'");
        $checkInvites->execute();
        $inviteCheck = $checkInvites->rowCount();

        $checkQueue = $db->prepare("SELECT id FROM inviteQueue WHERE email = '$email'");
        $checkQueue->execute();
        $queueCheck = $checkQueue->rowCount();

        $checkUsers = $db->prepare("SELECT id FROM users WHERE email = '$email'");
        $checkUsers->execute();
        $usersCheck = $checkUsers->rowCount();

        $getInvite = $db->prepare("SELECT code FROM invites WHERE email = '$email' LIMIT 0, 1");
        $getInvite->execute();
        $inviteCode = $getInvite->fetchColumn();
    }catch(PDOException $e) {
        $invError++;
        $errorMessage = "A Database error occured." . "\n";
    }

0 个答案:

没有答案