use php pdo to update datetime column with current time using mysql

How would this be done?
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
If you want the "current time" do not use a DATETIME column.  Instead use a TIMESTAMP column.  The column will record the latest time that the row was changed, no matter what column was changed.  UPDATE queries that do not change any data will not change the TIMESTAMP column.

If you really want to update a DATETIME column, make a string variable with date('c') and use the SQL UPDATE query to change the value in the column.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zappafan2k2Commented:
Ray's suggestion is certainly a much better solution.  However, not all RDBMs support the same type of timestamp data type, so you may want to keep the datetime field if you ever need to migrate.

That said, to further the last sentence of Ray's answer, you don't even need to use PHP's date function; you can simply use MySQL's now() function instead.
UPDATE mytable SET myDateTimeField = now() WHERE <conditions>

Open in new window

0
rgb192Author Commented:
Ray's idea is the best better than I thought when asking question
and the zappafan2k2 is the answer to the question.
0
Ray PaseurCommented:
Thanks for the points.  Be aware that PHP and MySQL use different time-keeping strategies.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.