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 41 42 43 44 45 46 47
|
<?php
require 'PersonnageBDD.class.php';
class PersonnageManager
{
private $_db;
public function __construct($db)
{
$this->setDb($db);
}
public function add(PersonnageBDD $perso)
{
$insertion = $this->_db->prepare('INSERT INTO personnages SET nom = :nom, forcePerso = :forcePerso, degats = :degats, niveau = :niveau,experience = :experience');
$insertion->bindValue(':nom', $perso->nom());
$insertion->bindValue(':forcePerso', $perso->forcePerso(),PDO::PARAM_INT);
$insertion->bindValue(':degats', $perso->degats(), PDO::PARAM_INT);
$insertion->bindValue(':niveau', $perso->niveau(), PDO::PARAM_INT);
$insertion->bindValue(':experience', $perso->experience(),PDO::PARAM_INT);
$insertion->execute();
}
public function setDb(PDO $db)
{
$this->_db = $db;
}
}
$persoBDD = new PersonnageBDD(array(
'nom' => 'Victor',
'forcePerso' => 5,
'degats' => 0,
'niveau' => 1,
'experience' => 0
));
$db = new PDO('mysql:host=localhost;dbname=testspoo', 'root', '');
$manager = new PersonnageManager($db);
$manager->add($persoBDD);
?> |
Partager