PDO Exception Questions - How to Catch Them

后端 未结 3 1709
夕颜
夕颜 2020-12-01 14:20

I\'m using PDO to re-write a website interface for a database. I used to use the mysql extension, but I had never bothered with error handling, and the few error handlers I

3条回答
  •  情深已故
    2020-12-01 14:38

    prepare("INSERT INTO tbl_user (id, name, password, question, answer) VALUES (NULL, :name, :password, :question, :answer)");
    
        $stmt->bindValue(":name", $_POST['name']);
        $stmt->bindValue(":password", $_POST['password']);
        $stmt->bindValue(":question", $_POST['question']);
        $stmt->bindValue(":answer", $_POST['answer']);
        $inserted = $stmt->execute();
    
        if($inserted)
            echo "Successfully added the new user " . $_POST['name'];
        else
            echo "Somethig get wrong";
    ?>
    

提交回复
热议问题