Jump to content

inserting date and time using PEAR db


paulie

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);
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)
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.