Jump to content


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


inserting date and time using PEAR db

Recommended Posts

I am attempting to enter information, typed into an HTML form, into an Oracle database. I have been able to do this successfully with the following code:

$dsn = "odbc://$user:$pass@$host/$database";
$db = DB::connect($dsn);
die ($db->getMessage());

$table_name = 'engineers_worksheet';

$fields_values = array(
'pk_worksheet_id' => $pk_no,
'unit_id' => $unitno,
'asset_name' => $regno,
'asset_make' => $makemod,
'customer' => $client,
'site_address' => $siteadd,
'asset_set_point_temp' => $celsius,
'asset_defrost_interval_hrs' => $defrost,
'unit_status' => $status,
'asset_condition' => $condition,
'lights_working_before' => $lightsb,
'lights_working_after' => $lightsa,
'asset_defects' => $defects,
'work_done' => $work,
'parts_used1' => $parts1,
'parts_used2' => $parts2,
'parts_used3' => $parts3,
'parts_used4' => $parts4,
'parts_used5' => $parts5,
'parts_used6' => $parts6,
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]'start_time' => $start,[!--colorc--][/span][!--/colorc--]
[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]'end_time' => $finish,[!--colorc--][/span][!--/colorc--]
'engineer' => $psswd

$res = $db->autoExecute($table_name, $fields_values,

if (PEAR::isError($res)) {

I have highlighted the start_time and end_time parts of the code because, although I have been successful in entering a date into the dataebase, I would also like a time value to be entered.

Does anybody know of any way to format the variable, similar to SQL formatting of date and time, so that both date and time will be entered into the database? i.e.
'start_time' => ($start, 'DD-MON-YY HH24:MI:SS)

Share this post

Link to post
Share on other sites
You don't say what $start and $finish are, but this example assumes they are unix timestamps. If they are not, you'll need to either convert them or use something else because this won't work.

[code]Array('start_time' => date('d-m-Y H:i:s', $start),
'end_time' => date('d-m-Y H:i:s', $finish));[/code]

Share this post

Link to post
Share on other sites
thanks for the reply. The variables $start and $finish both contain the following data $time=time();
$start=date("d-M-y G:i:s", time());

I tried the code but it came back with an unknown DB error

Share this post

Link to post
Share on other sites


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.