PHP / Zend Framework Timestamp problem

For programming and general questions on Zend Framework

PHP / Zend Framework Timestamp problem

Postby zfcrazy on Thu Feb 16, 2012 5:26 pm

Hi

I have a script that was developed and can no longer reach the developer. It's not old either.

Anyhow, it was running fine on a dedicated server with WHM, Cpanel... but I recently had to move to a new host.

I made sure the new host server matched the old server. Same php, apache, mysql... just slightly newer version of cpanel.

I went through all of the php options and made sure set up the same. Checked locales too.

PROBLEM:

Throughout the code, there are two methods used to capture datetime value.

Code: Select all
'timestamp' => new Zend_Db_Expr('NOW()'),

OR
Code: Select all
$action->timestamp = date('Y-m-d H:i:s');


I've made sure that the value is right, by placing a mail() near these kinds of lines to send me the value generated. It's correct.

But... the value is given to zend framework which handles the mysql insert, the value in the datetime field ends up as 0000-00-00 00:00:00

I don't know much about zend framework... but it's driving me crazy. I changed the datetime type to varchar and the value zend framework attempts to insert is just 2012... so mysql is not accepting that value and results in 0000-00-00 00:00:00

I have no idea why it's doing this. Same code, almost identical server setup.

Couple differences with the new server is that it has suhosin and mod_security installed. But I dont know why that would make difference.

I would be grateful for any suggestions.

Thank you
zfcrazy
 
Posts: 3
Joined: Thu Feb 16, 2012 5:19 pm

Re: PHP / Zend Framework Timestamp problem

Postby frank_thoeny on Sun Feb 26, 2012 10:37 am

Here is a timestamp solution for you.

MySQL set your timestamp column type to DATETIME and leave Default set to none. This is very important because of the way Zend/PHP make the date into timestamps.

This is an example of a timestamp that updates every time a user logs in successfully.
Code: Select all
    public function loginSucess(Application_Model_Users $users)
    {
        $data['ts_last_login'] = date('Y-m-d H:i:s');           
        $this->getDbTable()->update($data, array('user = ?' => $users->getUser()));       
    }

Good Luck!
frank_thoeny
 
Posts: 10
Joined: Wed Feb 22, 2012 10:23 pm

Re: PHP / Zend Framework Timestamp problem

Postby zfcrazy on Wed May 16, 2012 12:16 am

Thank you for the suggestion... I just saw your message. I have looked and that is how the column is set up.

There must be something causing this... same code and tables which operated just find on last server. I have spent hours and hours trying to fix this and haven't gotten anywhere.
zfcrazy
 
Posts: 3
Joined: Thu Feb 16, 2012 5:19 pm

Re: PHP / Zend Framework Timestamp problem

Postby zfcrazy on Wed May 16, 2012 5:58 pm

I replaced all php date() with new Zend_Db_Expr('NOW()'); and problem gone... hopefully that won't become a performance hit.
zfcrazy
 
Posts: 3
Joined: Thu Feb 16, 2012 5:19 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 7 guests