I am writing a new website that uses PHP and MySQL. I am trying to do this using OO and would welcome a bit of advice.
I know that I should structure the class as follows but what I am not sure about is whether I should create separate methods for accessing the database to insert, update etc. the name.
Does it matter? Should I have separate methods or can I just roll the code into set_name and get_name?
<?php
class person {
var $name;
function set_name($new_name) {
$this->name = $new_name;
}
function get_name() {
return $this->name;
}
}
?>
You might be interested in Object-relation-mapping and/or specifically the Active Record Pattern as a starter. See also this example for a implementation.