There is Redbean ORM . What I did was basically wrap my own code around a domain object, so it looks like
class Book extends RedBean_DomainObject { public function __construct($id) { if ($id!=0) $this->find($id); } public function save_details($author, $title) {
The code checks for a bean; if that happens, he will download it. You assign properties to the class and call the save () method to save it to the bean. RedBean ORM will automatically detect if this is a save or update. Note The RedBean domain object has been replaced with something better.
I also use WordPress wp-db and I like the syntax
$wpdb->insert("books", array('title' => $title, 'author' =>$author));
I found a little online wrapper that allows me to do INSERT ... ON DUPLICATE KEY too.
$wpdb->insert_on_duplicate("author_book_relationship", array('book_id' => $book_id, 'date_published' =>$date_published), array('book_id' => $book_id));
The first parameter is the table, the second is the insert / update information, and the last is the where clause for the UPDATE part.
Edit
I usually wrap SQL functions in a helper
class BookHelper { public function save_relationship($id, $book, $author) { global $wpdb; $wpdb->insert_on_duplicate("author_book_relationship", array('book_id' => $book_id, 'date_published' =>$date_published), array('book_id' => $book_id)); } }
And inside the strategy
class BookSaveStrategy { protected $book_helper; public function save_relationship($id, $book, $title) {
What can be used in the controller
if (isset($_POST['save_book'])) { $book_save_strategy->save($_POST['id'], $_POST['author'], $_POST['title']); }