Petit nouveau ! |
2 Messages
07 mars 2020, 19:34
Merci de la réponse, mais elle appelle quelques explications, je ne comprends pas tout ?
Voici 1) le message d'erreur complet :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM fiches WHERE idFich = 17' at line 1 in C:\EasyPHP-Devserver-17\eds-www\fich_tech\classes\Database.php:37 Stack trace: #0 C:\EasyPHP-Devserver-17\eds-www\fich_tech\classes\Database.php(37): PDOStatement->execute(Array) #1 C:\EasyPHP-Devserver-17\eds-www\fich_tech\admin\Delete_fich.php(16): Database->query('DELETE * FROM f...') #2 {main} thrown in C:\EasyPHP-Devserver-17\eds-www\fich_tech\classes\Database.php on line 37
2) Le fichier Database complet
<?php
class Database{
private $host = 'localhost';
private $username = 'root';
private $password = '';
private $database = 'fiches_cuisine';
private $db;
public function __construct($host = null, $username = null, $password = null, $database = null){
if($host != null){
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
try{
$this->db = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->username, $this->password, array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
}catch(PDOException $e){
die('<h1>Impossible de se connecter à la base de donnée</h1>');
}
}
public function query($sql, $data = array()){
$req =$this->db->prepare($sql);
$req->execute($data);
return $req->fetchAll(PDO::FETCH_OBJ);
}
}
?>
et 3) la partie du fichier qui pose problème, j'ai la même chose avec update et insert into mais pas avec select ??
$DB = new Database();
if(!empty($_GET['id']))
{
$id = ($_GET['id']);
}
if(!empty($_POST))
{
$id = ($_POST['id']);
$DB->query('DELETE * FROM fiches WHERE idFich = ' . $id . '');
header("Location:/fich_tech/admin/List_fich.php");
}