public function add(Client $client) { $q = $this->_db->prepare('INSERT INTO client SET numero = :numero, nom = :nom, prenom = :prenom, adresse= :adresse, referent = :referent'); $q->bindValue(':numero', $client->numero(), PDO::PARAM_INT); $q->bindValue(':nom', $client->nom(), PDO::PARAM_STR); $q->bindValue(':prenom', $client->prenom(), PDO::PARAM_STR); $q->bindValue(':adresse', $client->adresse(), PDO::PARAM_STR); $q->bindValue(':referent', $client->referent(), PDO::PARAM_STR); $q->execute(); return self::ACTION_REUSSIE; }
public function update(Client $client) { $query = $this->_db->prepare('UPDATE t_client SET nom=:nom, adresse=:adresse, telephone1=:telephone1, telephone2=:telephone2, cin=:cin, email=:email WHERE id=:id') or die(print_r($this->_db->errorInfo())); $query->bindValue(':nom', $client->nom()); $query->bindValue(':adresse', $client->adresse()); $query->bindValue(':telephone1', $client->telephone1()); $query->bindValue(':telephone2', $client->telephone2()); $query->bindValue(':cin', $client->cin()); $query->bindValue(':email', $client->email()); $query->bindValue(':id', $client->id()); $query->execute(); $query->closeCursor(); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta charset="utf-8" /> <link rel="stylesheet" href="style.css" /> <title>TestClient</title> <?php require '../objects/Client.class.php'; $client = new Client(['numero' => '12345', 'nom' => 'daho', 'prenom' => 'e', 'adresse' => 'Paris', 'referent' => 'marc']); echo $client->nom(); echo $client->referent(); print_r($client); $client->setAdresse('lyon'); echo $client->adresse(); ?> <body> </body> </html>