Php – Zend_Db is ignoring the default field values!

PHPzend-dbzend-db-tablezend-framework

I'm using Zend Framework 1.7 with a MySQL 5.0 database for a project I'm doing. Part of the system is a longish form that asks a user for various dates (in dd/mm/yyyy format) as well as some integer fields.

In my MySQL table, all these fields have a default of null. When I come to save the form data with a function in my model (which extends Zend_Db_Table), any blank integers fields are set to 0, and any blank date fields are set to 0000-00-00 – in both cases, they should be null.

I believe this is because Zend_Db_Table->insert() is quoting all values, including blank ones. Is there any way I can alter this behaviour? I'm currently having to loop through groups of fields, setting them to null as appropriate.

Cheers,
Matt

Best Answer

Try:

$data['shouldBeEmtpy'] = new Zend_Db_Expr('NULL');
Related Topic