Have a look at some existing PDO wrappers, there are many out there. You code is pretty incomplete, so its difficult to say if it'll be functional. You have the $sql var, but I can't see how it's being passed to your methods.
In addition, simple CRUDs are usually just that - simple. Building a flexible crud is quite a challenge as you need to be able to build queries from clauses, so IMO, each CRUD method should accept clause arguments or at least there should be a way to access class variables that hold this data.
In particular, the class (again IMO), should be as general as possible. It should not be coupled to other classes or your DB schema as this will lead to maintenance and re-use problems later on if you decide to change the DB/classes or use it in a future project.
There's an article that I found interesting - the use of chained methods for binding parameters. There's no reason why this approach can't be used with clauses too: http://stackoverflow.com/questions/6740153/simple-pdo-wrapper
diafol
Keep Smiling
10,828 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,532
Skill Endorsements: 61
Depending on what you want to build, my code snippet may get you some ideas.
pritaeas
Posting Prodigy
9,533 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98
I like the bind method - it saves having to produce an array. Although, an array can sometimes be useful, especially if you have many substitutions.
$bind = array(':bind1'=>'foo1'... ':bind25'=>'foo25');
I'd rather write out an array than call a method 25 times.
public function arrayBind($arrBind) {
$this->stmt->bind($arrBind);
return $this;
}
Of course, you'd need to validate your data. But for the client, this may be invisible = cleaner code.
diafol
Keep Smiling
10,828 posts since Oct 2006
Reputation Points: 1,675
Solved Threads: 1,532
Skill Endorsements: 61
Question Answered as of 1 Month Ago by
diafol,
veedeoo
and
pritaeas