View Single Post
Old 08-22-2008, 11:54 AM   #1 (permalink)
Theo
The Wanderer
 
Join Date: Aug 2008
Posts: 11
Thanks: 4
Theo is on a distinguished road
Default Adding Timestamps in SQL?

Okay, this should be stupidly easy, but I can't figure it out :(

I have this table in my database:

PHP Code:
CREATE TABLE IF NOT EXISTS `articles` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
release_datetimestamp NOT NULL default CURRENT_TIMESTAMP,
  `
titlevarchar(100NOT NULL,
  `
contentlongtext NOT NULL,
  `
linkvarchar(100NOT NULL,
  `
author_idint(10unsigned NOT NULL,
  
PRIMARY KEY  (`id`),
  
KEY `release_date` (`release_date`,`author_id`),
  
FULLTEXT KEY `title` (`title`,`content`)
ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=
I'm trying to set the release date when I post a new article like this (using PDO to access a MySQL database):

PHP Code:
//    Construct our timestamp.    
$theTimestamp mktime000$_POST['month'], $_POST['day'], $_POST['year'] );
$theStatement $theDatabase->prepare( <<<_SQL_
    INSERT INTO `articles` 
    ( `release_date`, `title`, `content`, `author_id` )
    VALUES ( ?, ?, ?, ? )
_SQL_
    );
            
$theStatement->execute( array($theTimestamp$_POST['title'], $_POST['content'], $theSession['user_id'] ) ); 
Whenever I run this piece of code the timestamp ends up being stored in my table as 00000000000... (i.e. Wed 31st Dec 1969 ).

I have a section of code that previews the article and constructs the timestamp in exactly the same way and that works fine. Shouldn't this just work? What am I missing here?
Theo is offline  
Reply With Quote