Jump to content


Photo

inserting date and time using PEAR db


  • Please log in to reply
2 replies to this topic

#1 paulie

paulie
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 March 2006 - 10:56 AM

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);
if(DB::isError($db)){
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,
DB_AUTOQUERY_INSERT);

if (PEAR::isError($res)) {
die($res->getMessage());
}


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)

#2 kanikilu

kanikilu
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationDallas, TX

Posted 24 March 2006 - 02:41 PM

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.

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


#3 paulie

paulie
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 March 2006 - 03:10 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users