Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A better solution would be to create the table with a <code>timestamp</code> default. That way you would not have to insert anything into the table as far as the <code>timestamp</code> column is concerned.</p> <p>To do this you can either do the following on table creation,</p> <pre><code> `created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, </code></pre> <p>The above will auto set the <code>created</code> column to the time that the row data was inserted into the column.</p> <p>If you would like to have the column row auto update itself whenever the row is updated you can also do the following; this would be useful for a column which say for a forum displays the last updated or edited time of that post.</p> <pre><code>`updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, </code></pre> <p>You can read more about this here, <a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html</a>.</p> <p>Upon retrieving the value, to get a date like output from php use the date function.</p> <p>More information on the date function can be found here <a href="http://php.net/manual/en/function.date.php" rel="nofollow">http://php.net/manual/en/function.date.php</a>.</p> <p>It is also worth noting that your current code is not very well written and is open to SQL injection (<a href="http://en.wikipedia.org/wiki/SQL_injection" rel="nofollow">http://en.wikipedia.org/wiki/SQL_injection</a>), I would advise you to learn php's PDO (<a href="http://php.net/manual/en/book.pdo.php" rel="nofollow">http://php.net/manual/en/book.pdo.php</a>).</p> <p>PDO also has the advantage that if in the future you change databases it is not a very hard to do task while using PDO.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload