views:

262

answers:

1

I have complex logic which is not possible (too slow) to run through PHP with Doctrine, so I need to create a stored procedure for this. The logic also includes inserting/updating records in a table using the Timestampable behavior. How do I preserve this behavior in the stored procedure?

+1  A: 

If your schema uses the default Timestampable behaviour from Doctrine, then you have the created_at and updated_at datetime columns added to your table schema. Then I'd imagine that in your stored procedure, you can update both created_at and updated_at to the current date & time (using eg NOW()) if the record is new, and only updated_at if the record is existing.

This assumes that your stored procedure can differentiate between new and existing records.

richsage
No this won't work, the `NOW()` function in Mysql uses the datetime on the db server and the `time()` function in PHP uses the datetime on the application server. There is always an offset between both timestamps (which is not acceptable by design).
Ropstah
Ah I see. How are you calling your stored procedure - manually from PHP via direct SQL? Could you not pass in `time()` as a parameter?
richsage
Lol, of course I can add a parameter hahaha! Thanks.
Ropstah