// bonjour voila je voudrais faire un insert et un update met ma class db me le permet pas
// voici ma class db
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class DB{
 
	private $host = 'localhost';
	private $username = 'root';
	private $password = '';
	private $database = 'vente';
	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_WARNING
				));
		}catch(PDOException $e){
			die('<h1>Impossible de se connecter a la base de donnee</h1>');
		}
	}
 
	public function query($sql, $data = array()){
		$req =$this->db->prepare($sql);
		$req->execute($data);
		return $req->fetchAll(PDO::FETCH_OBJ);
	}
 
	public function prepare($sql, $data = array()){ // voici ma fonction prepare elle est pas bonne
		$req =$this->db->prepare($sql);
		$req->execute($data);
		return $req->fetch();
	}
 
}

// voila mon fichier pour mon update
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$DB = new DB();
$setting = $DB->query('SELECT * FROM setting');
if(isset($_POST['modifsite'])){
	$compagny = $_POST['compagny'];
	$mobile = $_POST['mobile'];
	$fax = $_POST['fax'];
	$email = $_POST['email'];
	$support = $_POST['support'];
	$rows = $_POST['rows'];
	$curency = $_POST['curency'];
	$adress = $_POST['adresse'];
  $sql = "UPDATE setting SET tittle='$compagny', mobile='$mobile', fax='$fax' WHERE id='1'";
  $req = $DB->prepare($sql);
 
    echo"<div id=\"toast-container\" class=\"toast-top-right\" role=\"alert\" aria-live=\"polite\"><div class=\"toast toast-info\"><button class=\"toast-close-button\" role=\"button\" type=\"button\">x</button><div class=\"toast-title\"></div><div class=\"toast-message\">dfsdfsdfsdfsd</div></div></div>";
 
}
?>