But the question is: where?
In pseudo code:
Code: Select all
class AuthorModel {
function save(){
$db->execute('insert into autors (name) values ($value)');
}
}
class PostModel{
function save(){
$db->execute('insert into posts (name, date) values ("$value", "$value")');
}
}
class CatModel{
function save(){
$db->execute('insert into cats (name) values ("$value")');
}
}
class BlogpostController{
function saveaction(){
$newauthor = new AuthorModel;
$newauthor->name = 'henrik';
$newpost = new PostModel;
$newpost->setdata('some new post', '12/23/2007');
$newcat = new catModel;
$newcat->name = 'php';
// now save all that using transactions
// start transaction here???
// commit here???
}
}Code: Select all
function save(){
$newblog = new blog;
$newblog->save($author, $posttitle, $postdate, $cat);
}Something like this?:
Code: Select all
class BlogPostModel{
function save(){
$transaction = new pdotransaction();
$transaction->execute('insert into autors (name) values ("henrik")');
$transaction->execute('insert into posts (name, date) values ("some new post", "12/23/2007")');
$transaction->execute('insert into cats (name) values ("php")');
$transaction->commit();
}
}Mind you, I'm just starting with this stuff, so I'm properly missing something obvious. But a few hints or even search terms I should look into so I can research some pattern would be helpful. I've read a lot about design patterns and understand most of them. But now that it comes to actually building something I'm at a loss somewhat. The thing is also, in each and every example I see online or in books, they deal with simple situations like saving and retrieving data from a single table. However, even if you're dealing with something relatively simple as a blog post, you're dealing with at least 3, 4 tables.