PHP INSERT Query Syntax

I'm not sure how to write the date in the following insert query.  NOW() does not work.

<?php
ee()->db->insert('exp_bicycle_addresses',
    							array(
       								'email_address'  => $be,
       								'bike_value' => $bv,
       								'bike_state' => $bs,
       								'date' => NOW(),
       								'ip' => $ip
    								)
								);
?>

Open in new window

LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Marco GasiFreelancerCommented:
I did exactly this way. If you don't need any special format for the date time, your code should give you exactly what you want...
Ray PaseurCommented:
What does NOW() do that makes you say it "does not work?"

You can define a column with TIMESTAMP and MySQL will always keep it up-to-date with the most recent INSERT or UPDATE.
Dave BaldwinFixer of ProblemsCommented:
NOW() works in MySQL but it does not work in PHP.  You have a PHP array above which is why it's not working.  To include it in an INSERT query for MySQL from that array, you will probably have to put it in quotes.  
'date' => 'NOW()',

Open in new window

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
Ray PaseurCommented:
^^ Good catch, Dave.  That's why "does not work" is  not a very good clue.  Undoubtedly there was some kind of run-time message about a missing PHP function.

For an overview of how to handle date/time information in PHP and MySQL, please see this article:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
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.