note 56123 added to function.date
| From: | anewphpuser at osu1 dot php dot net | Date: | Wed, 24 Aug 2005 09:14:36 +0000 |
| Subject: | note 56123 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94117@lists.php.net to get a copy of this message | ||
use php to get the current time and save it to the mysql database, then use php to read from the
database.
//////save_to_database.php//////
<?php
$date=time();
$date_display=date("d-F-Y", $date);
echo "display the current time before saving it to database:";
echo "<br>$data_display<br>";
$conn = mysql_connect("localhost","root","");
if (!$conn) die("mysql connection problem.");
mysql_select_db("databasename",$conn);
$sql = "insert into tablename (id, date) values (1, $date)";
$result = mysql_query($sql);
if (!$result) die("sql excute problem.");
echo "new entry inserted.";
mysql_close($conn);
?>
//////read_from_database.php//////
<?php
$conn = mysql_connect("localhost","root","");
if (!$conn) die("mysql connection problem.");
mysql_select_db("databasename",$conn);
$sql = "select * from tablename where id=1";
$result = mysql_query($sql);
if (!$result) die("sql excute problem.");
$content = mysql_result($result, 0, "date");
$content_display = date("d-F-Y",$content);
echo "The content is: $content_display";
mysql_close($conn);
?>
I've met a problem while saving the date to the database. The "display before saving"
bit goes well, and the sql has been excuted. A new entry has been inserted into the database.
BUT, the problem is that the new entry is always
"0000-00-00 00:00:00" instead of the current time.
So when I read from the database, it can only display the content as: 01-January-1970.
Is there anyone can help?
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56123
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56123&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56123&report=yes
Search -- http://master.php.net/manage/user-notes.php