Jump to content

Using PHP to save system date in Oracle table


Recommended Posts

I am attempting to write a php code to do an internal on line survey.  We want to date stamp the answers to the survey questions and store them in Oracle.

I know how to get the system date using the date function in PHP, but I"m having trouble actually storing it in a date type field in Oracle

  • 1 month later...

There are two ways to do this. If you want to store the date from the database server, you would execute a query like this:

 

insert into table(field)values(sysdate)

 

If you want to store the date from the web server, you would do this:

 

$current_time = date("d M Y H:i:s");

$insert = OCIParse($DB, "insert into table(field)values(to_date(:value, 'dd Mon yyyy hh24:mi:ss'))");

ocibindbyname($insert, ":value", $current_time);

OCIExecute($insert);

OCIFreeStatement($insert);

 

 

 

Of course, if your database and your web server reside on the same machine, it doesn't matter which one you use. It only matters if they're on two different machines and the clocks are off.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.