What is the equivalent of bind_result on PDO

后端 未结 4 1950
无人共我
无人共我 2020-12-07 02:06

I\'m converting to PDO and Im using prepared statements, I want to bind my result as so $stmt->bind_result($email_count); so i am able to put this into an if

4条回答
  •  眼角桃花
    2020-12-07 02:27

    You do not need an ugly bind_result with PDO at all.

    Yet you don't need to count either. Please, avoid unnecessary actions - they only bloat and obfuscate your code for no reason.

    Think first, what you need from the query? Do you really need to count? No. What you actually need is just a flag - if user exists or no. So, make a query to return such a flag.

    $stmt = $this->pdo->prepare("SELECT 1 FROM users WHERE email=?");
    $stmt->execute(array($_POST['email']));
    $exists = $stmt->fetchColumn();
    

    Same goes for all the other parts of code

    //escape the POST data for added protection
    

    You don't actually "escape" any data in this code block and add no protection. Yet I see absolutely no point in inserting NULL as email. Are you sure you really want it?

提交回复
热议问题