8768 sujets

Développement web côté serveur, CMS

Bonjour la communauté,
je monte un site et je voudrais permettre à l'utilisateur de supprimer son compte quand il le souhait. J'ai cette erreur qui apparaît
Fatal error: Uncaught Error: Call to undefined method Db::exec() in C:\wamp\www\ndameyong\delete.php:31 Stack trace: #0 {main} thrown in C:\wamp\www\ndameyong\delete.php on line 31
je besoin de votre aide svp
voila le fichier Db.php
<?php
 
/**
* Gestion de la base de données
*/
class Db{
     
    private $host=HOST;
    private $name=DBNAME;
    private $user=USER;
    private $pass=PWD;
 
    private $connexion;
 
    function __construct($host=null,$name=null,$user=null,$pass=null){
         
        if($host != null){
            $this->host = $host;
            $this->name = $name;
            $this->user = $user;
            $this->pass = $pass;
        }
 
        try{
 
            $this->connexion = new PDO('mysql:host='.$this->host.';dbname='.$this->name,
                $this->user,$this->pass,array(
                    1002 =>'SET NAMES UTF8',
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING


              
                    ));
            $this->connexion->exec('SET NAMES utf8');
//PDO::MYSQL_ATTR_INIT_COMMAND
        }catch (PDOException $e){
            //echo 'Erreur : Impossible de se connecter  à la BD !';die();
            echo $e->getMessage();
        }
    }
 
    /* requete */
 
    public function query($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $req->execute($data);
        return $req->fetchAll(PDO::FETCH_OBJ);
    }
 
    public function tquery($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $req->execute($data);
        return $req->fetchAll(PDO::FETCH_ASSOC);
    }
 
 
    public function insert($sql , $data=array()){
        $req = $this->connexion->prepare($sql);
        $nb=$req->execute($data);
        return $nb;
    }
 
    public function uniqueEmail($email){
        $req = $this->connexion->prepare('SELECT count(*) as nbre from users WHERE email=:email limit 1');
        $req->execute(array('email'=>$email));
 
        $reponse = $req->fetchAll(PDO::FETCH_ASSOC);
        return $reponse[0]['nbre'];
 
    }


    public function exec($sql , $data=array()){
      try{
        $req = $this->connexion->prepare($sql);
        $req->execute($data);
        return $req->rowCount(); // Retourne le nombre de lignes impactées par la reuqête
      }catch(Exception $e){
        echo 'Erreur : ' . $e->getMessage(); // en cas d'erreur dans la requête !
      }
    }
}


delete.php
<?php require 'includes/includes.php';

if(!Auth::islog($DB)){
    header('location:index.php');
    exit(); 
    }

if(empty($_SESSION['user'])){
  header('Location: login.php');
}

$user = $_SESSION['user'];

$filePath = 'photos/'.$user["id"].'/'.$user['photo'];

$dir = new DirectoryIterator(dirname('photos/'.$user['id']));

foreach($dir as $fileinfo){
	if(!$fileinfo->isDot()){
		unlink($fileinfo->getPathname());
	}
}

if($user['photo'] && file_exists($filePath) && is_file($filePath)){
	unlink($filePath);
	rmdir('photos/'.$user->id);
}

$sql = 'DELETE FROM users WHERE id=:id';
$data = [':id'=>$user];
$del = $DB->exec($sql , $data) ;


unset($_SESSION['user']);
session_destroy();
header('Location: index.php');