After spending the last year flipping back and forth between C# MVC and WordPress one of the things I really miss in WP is Entity Framework (EF). I am aware that there are various ORM projects out there, but I have chosen to work exclusively in SQLite across all platforms, from Kiosks to web apps to mobile apps to the extent possible. On top of that 99% of what I need to do can be handled automatically with a few simple naming conventions with overrides if you insist.

All of these functions are instance methods of AppMagicSystem. I think I will go with a descendant class if there is any demand for a heavier DB automation layer, but I am not certain you need it. That is if you design your database suitable to the task at hand. If you consider that most CReate and Update in CRUD is really simple, so also should be the solution. The client passes an object to the server and either a new entry is created or values in an existing entry are updated.

AppMagic in any PHP flavor is based on PDO for its internal database. PDO offers the fetch option PDO::FETCH_CLASS which returns a populated instance of the class specified by the $classname string. What it does not have are methods to insert or update classes. This is the point at which Object Relationship Management (ORM) comes in. For routine CRUD operations what we need the most is a super simple way to show a form and add or update a record, add a record based on a Paypal IPN hit or other simple CRUD processes we need the simplest of solutions. 

The basic functions that underlie our simple CRUD system are:

  • InsertObject()
  • UpdateObject()
  • class AppMagicDbView

I have adapted the EF table naming convention, but without the fancy dictionary to determine whether to append “s” or “es”. All table names must be named [classname]s to enjoy full automation, so if your class is Bird, then your table is Birds. If you insist on a nonconforming table name the functions take an optional string parameter $table_name for that purpose.

The point of exposing these functions directly is to allow for both the simple rapid development of CRUD systems, but also to allow both application and plugin developers to create custom recursion systems in the event that the ones I include do not suit your needs.

Have a look at the individual components for examples of usage.