Monthly Archives: April 2007

Forays into PHP and MySQL

I’ve just started working extensively with PHP and MySQL.  Here’s a simple tip that took me a while to figure out (despite copious examples on PHP.net, I couldn’t find this one:

My MySQL table has a  Timestamp (Z) field, used to assign the current date and time to it when a record is added. Using mySQL in PHP, I can assign the value to it like this:

$result=mysql_query(“INSERT INTO qNotices (nPostDateTime) VALUES(NOW()”);

or I can assign the value with a PHP assignment statement, using this:

  $nPostDateTime= date(‘YmdHis’);  // Same as NOW() MySQL function.
 $result=mysql_query(“INSERT INTO qNotices (nPostDateTime) VALUES($nPostDateTime”);

Note that you do not need any dashes or semi-colons in the format string here, even though the field looks like this :  2007-04-19 10:23:32 when you view the data with a SELECT statement.