Thursday, June 21, 2012

PHP default time stamp in MySQL




When I created a edu_payments table in MySQL
CREATE TABLE  `cnsh_lms`.`edu_payments` (
  `payment_id` smallint(5) unsigned NOT NULL auto_increment,
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `approved` tinyint(4) NOT NULL default '0',
  `transaction_id` char(100) NOT NULL,
  `member_id` mediumint(8) unsigned NOT NULL,
  `course_id` mediumint(8) unsigned NOT NULL,
  `amount` decimal(7,2) NOT NULL default '0.00',
  PRIMARY KEY  (`payment_id`)
) ENGINE=MyISAM   DEFAULT CHARSET=utf8;


`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
will  automatically  set to the current timestamp when the record is created if the column is set to NULL or is not specified at all.

For example
 INSERT INTO edu_payments VALUES ('', NULL, 0, '', '{$_SESSION['member_id']}', '$module_id', 0)
I put the NULL in timestamp and  the time display as 2012-06-21 16:25:22
1, 2012-06-21 16:25:22, 1, '1234', 16, 104, 27.00

When you insert the time, the timestamp should have similar format.
      $payment_id =1;
         $amount=27;
         $tran_id=1234;        
        $data=date('y-m-d G:i:s ');
        $sql = "UPDATE edu_payments SET  timestamp='$data', approved=1, transaction_id=$tran_id, amount=$amount WHERE payment_id=$payment_id";

i.e. input date should have   $data=date('y-m-d G:i:s '); where G is for 24 hours and g is for 12 hours

No comments:

Post a Comment