I don't know if you are familar with Zend Framework, but this is what I have been trying to learn for the past couple days.
As chance would have it, I just received this in an email from the ZF mailing list. Someone else was asking a similar question to mine.
PHP Code:
public function insert(array $data)
{
$data = array_intersect_key($data, array_fill_keys($this->info('cols'), ''));
return parent::insert($data);
}
public function update(array $data, $where)
{
$data = array_intersect_key($data, array_fill_keys($this->info('cols'), ''));
return parent::update($data, $where);
}
In the above example $this is an instance of Zend_Db_Table. Basicly it turns a table from your database into an object. All it takes to do this is extending Zend_Db_Table, giving the new class the same name as your table, and supplying one variable that has the same name as your table. It is two lines of code, then you can call $this->insert() like above to do an insert query as long as you are feeding it an array with key values that match your column names. This is Awesome.
J
Bookmarks