Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'connection.php';
- $con = new connection();
- class cliente{
- private $nome;
- private $email;
- private $senha;
- private $cpf;
- function cliente($nome,$email,$senha,$cpf){
- $this->nome = $nome;
- $this->email = $email;
- $this->senha = $senha;
- $this->cpf = $cpf;
- }
- //CRUD stands for Create, Read, Update and Delete
- //The function below create a new data for our database
- public function getNome(){
- return $this->nome;
- }
- public function register(){
- try{
- $stmt = $con->prepare("INSERT INTO clientes (cpf,nome,email,senha) VALUES (?,?,?,?)");
- $stmt->execute([$this->cpf,$this->nome,$this->emial,$this->senha]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- }
- //this function show data that is in our data base
- public function showData(){
- try{
- $stmt = $con->prepare("SELECT nome,cpf,email FROM clientes");
- while ($data = $stmt->fetch()) {
- echo "Nome: ".$data['nome']. "<br>CPF: ".$data['cpf']."<br>E-mail: ".$data['email'];
- }
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- }
- /*this function will update data inside the database. In that case I'll create a switch statement to choose between the places to be updated.
- */
- public function upDateData($option,$cpf,$nome,$email,$senha){
- switch ($option) {
- case 1:
- try{
- $stmt = $con->prepare("UPDATE clientes SET nome = ? WHERE cpf = ?");
- $stmt->execute([$nome,$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- break;
- case 2:
- try{
- $stmt = $con->prepare("UPDATE clientes SET email = ? WHERE cpf = ?");
- $stmt->execute([$email,$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- break;
- case 3:
- try{
- $stmt = $con->oreoare("UPDATE clientes SET senha = ? WHERE cpf = ?");
- $stmt->execute([$senha,$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- break;
- case 4:
- try{
- $stmt = $con->prepare("UPDATE clienes SET cpf = ? WHERE cpf = ?");
- $stmt->execute([$cpf,$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- break;
- case 5:
- try{
- $stmt= $con->prepare("UPDATE clientes set cpf = ?,nome= ?, email = ?, senha = ? WHERE cpf = ?");
- $stmt->execute([$cpf,$nome,$email,$senha,$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- break;
- default:
- echo "Choose something to be updated!";
- break;
- }
- }
- //this is the last function of CRUD, it'll be responsible for delete the specific data from our database.
- public function deleteData($cpf){
- try{
- $stmt = $con->prepare("DELETE FROM clientes WHERE cpf = ?");
- $stmt->execute([$cpf]);
- }catch(PDOExcepition $e){
- echo 'ERROR: '.$e->getMessage();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement