also, forget writing all of this code to manage the database, and use this instead...
http://www.phpobjectgenerator.co…