By Alvin Alexander. Last updated: June 4, 2016
Nothing major here, just an example MySQL PHP UPDATE query (really, a PHP SQL UPDATE query example that happens to use a MySQL database). For all the things I've done lately with PHP, I think this is the first PHP update query I've written, and I wanted to put an example out here so I can find it easily later.
So, with no further ado, here is a simple MySQL PHP update query example:
// connect to the mysql database $link = mysql_connect('localhost', 'USERNAME', 'PASSWORD'); if (!$link) { die('Could not connect: ' . mysql_error()); } // select our mysql database name mysql_select_db ('drupal'); // i'm skipping all my Node work here. // suffice it to say i have a node object i'm working with. $t = time(); // execute the php update query $query = "update node set changed=$t where nid=$node->nid"; mysql_query($query); // all done, shut 'er down mysql_close($link);
FWIW, this PHP update query example was created to work with a Drupal database, and that's where the "node" database table comes from.