public function add(Voiture $voiture) { $q = $this->_db->prepare('INSERT INTO voiture SET immatriculation = :immatriculation, marque = :marque, type = :type, annee= :annee, kilometrage = :kilometrage, date_arrivee = :date_arrivee, proprietaire = :proprietaire'); $q->bindValue(':immatriculation', $voiture->immatriculation(), PDO::PARAM_STR); $q->bindValue(':marque', $voiture->marque(), PDO::PARAM_STR); $q->bindValue(':type', $voiture->type(), PDO::PARAM_STR); $q->bindValue(':annee', $voiture->annee(), PDO::PARAM_INT); $q->bindValue(':kilometrage', $voiture->kilometrage(), PDO::PARAM_INT); $q->bindValue(':date_arrivee', $voiture->date_arrivee(), PDO::PARAM_INT); $q->bindValue(':proprietaire', $voiture->proprietaire(), PDO::PARAM_INT); $q->execute(); return self::ACTION_REUSSIE; }
<!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>TestVoiture</title> <?php require '../objects/Voiture.class.php'; $voiture = new Voiture(['immatriculation' => 'abc-123-38', 'marque' => 'peugeot', 'type' => 'sport', 'annee' => 1993, 'kilometrage' => '120000', 'date_arrivee' => '2001', 'proprietaire' => 'daho']); echo $voiture->annee(); echo $voiture->immatriculation(); print_r($voiture); $voiture->setAnnee(1900); echo $voiture->annee(); ?> <body> </body> </html>