Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- Formatting my post
- Notepad++ - Add C++ compiler
- Install PHPMailer 5.2.4 and use smtp gmail
- Wayback Machine - see archived versions of web pages across time
- Set up a child account and set screen time limit in Windows 8
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHP ibm_db2 extension in Linux (redHat)
- PHP: add a download as pdf file button in report page
Monday, March 18, 2013
MySQL, add a new column with modify time
I have a table cesei_member_extra:
CREATE TABLE cnsh_lms.`cesei_member_extra` (
`member_id` mediumint(8) unsigned NOT NULL,
`dept_type` tinyint(4) NOT NULL DEFAULT '0',
`edu_type` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Now I want to add a modification time, i.e. new column modify_date
ALTER TABLE cnsh_lms.`cesei_member_extra` ADD COLUMN modify_date datetime default '0000-00-00 00:00:00';
which equal to:
CREATE TABLE cnsh_lms.`cesei_member_extra` (
`member_id` mediumint(8) unsigned NOT NULL,
`dept_type` tinyint(4) NOT NULL DEFAULT '0',
`edu_type` tinyint(4) NOT NULL DEFAULT '0',
`modify_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
To get current time stamp with format '0000-00-00 00:00:00' in PHP:
$modify_date = date('Y-m-d H:i:s');
To insert the new vaules in table cesei_member_extra :
$sql = "REPLACE INTO cesei_member_extra VALUES ($member_id,$dept,$edu, '$modify_date')";
mysql_query($sql, $db);
Note: using '$modify_date' instead of $modify_date as it is a string or an error will be produced.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment