I have a question and want to know if my class is considered object oriented.
class Player {
private $db
function __construct($db) {
$this->db = $db;
}
public function set_player($name, $position, $number, $team) {
try {
$sql = 'INSERT INTO players SET playername = :playername, position = :position, teamid = :teamid, jersey = :jersey';
$this->db->prepare($sql);
$s->bindValue(':playername', $name);
$s->bindValue(':teamid', $team);
$s->bindValue(':position', $position);
$s->bindValue(':jersey', $number);
$s->execute();
} catch (PDOEXception $e) {
echo 'Could not add player, please try again.';
exit();
}
}
public function get_player($id) {
$result = $this->db->query('SELECT * FROM players WHERE id =' . $id);
$row = $result->fetch(PDO::FETCH_OBJ);
return $row;
}
}
In another file I will use this class in this way
include_once('./includes/global.php');
$player = new Player($pdo);
$player->set_player(Chris, Forward, 13, 1);
echo $player->get_player(1)->playername;
echo $player->get_player(1)->position;
$id
! \$\endgroup\$ – Alex L Dec 27 '15 at 0:31