Jump to content

timestamp is 0000-00-00 00:00:00 in database


clankill3r

Recommended Posts

$pubDate:

 

Thu, 01 Dec 2011 20:22:52 +0100

 

$timestamp = strtotime($pubDate);

gives:

1322767372

 

so that seems to be ok.

Also i get no query errors for inserting, only all values it inserts are  0000-00-00 00:00:00

 

I tried different setting in my database, this was the last:

 

# Kolom       Type               Collatie Attributen                                         Null     Standaardwaarde                   Extra

5 timestamp timestamp         on update CURRENT_TIMESTAMP Nee       CURRENT_TIMESTAMP ON      UPDATE CURRENT_TIMESTAMP

 

Link to comment
Share on other sites

thanks, the insert works now.

 

One more thing, i have a function to check if something is inserted:

 

function timeStampExists($pubDate) {
//$query = "SELECT * FROM articles WHERE timestamp='$timestamp'"; 
$query = "SELECT * FROM articles WHERE timestamp='STR_TO_DATE('$pubDate', '%a, %d %b %Y %T')'"; 
$res = mysql_query($query); 
if (mysql_num_rows($res) > 0) { 
	return true;
} else {
	return false;
} 
}

 

I only get this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /

on this line:

 

if (mysql_num_rows($res) > 0) {

 

Link to comment
Share on other sites

  • 4 months later...

Hi,

 

Sorry to open this older post, but since my question connects so much to this topic, I hope somebody could help me out with something I must be doing wrong:

 

I load rss-feeds into my database and receive  0000-00-00 00:00:00 results in the mysql column pubdate (DATETIME type) when using:

 

mysql_query("INSERT INTO rss_feeds (id, title, description, link, pubdate) 
VALUES (
'', 
'".mysql_real_escape_string($item->title)."', 
'".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
'".mysql_real_escape_string($item->link)."', 
'".mysql_real_escape_string($item->pubdate)."')");

 

With the solution given in this topic I tried several combinations of $item->pubdate and STR_TO_DATE but my codes give errors al the time.

mysql_query("INSERT INTO rss_feeds (id, title, description, link, pubdate) 
VALUES (
'', 
'".mysql_real_escape_string($item->title)."', 
'".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
'".mysql_real_escape_string($item->link)."', 
'".mysql_real_escape_string(STR_TO_DATE('$item->pubdate', '%a, %d %b %Y %T')."')");

 

It must be something simple but I cant find it.. Anybody who wants to help me out?

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.