4.3. PHP-Nuke upgrade scripts

What's in an upgrade script? Let's take a few representative examples of code and explain what they do, so that you get an idea of what is going on in such a script[1]:

UPDATE (Version number):

the PHP-Nuke version is updated in the nuke_config table through the UPDATE command:

// <application>PHP-Nuke</application> Version Number Update
$db->sql_query("UPDATE ".$prefix."_config SET Version_Num='6.7'");
UPDATE (Forums):

some forum parameters are modified through the UPDATE command.

// <application>PHP-Nuke</application> Forums Update
$db->sql_query("UPDATE ".$prefix."_bbconfig SET config_value='.0.4' where
config_name='version'");
$db->sql_query("UPDATE ".$prefix."_bbconfig SET config_value='3600' where
config_name='session_length'");
INSERT:

some values are inserted into the nuke_bbconfig table through the INSERT command:

$db->sql_query("INSERT INTO ".$prefix."_bbconfig VALUES ('config_id','1')");
DELETE:

a recorde is deleted from the nuke_headlines table through the DELETE command

$db->sql_query("DELETE FROM ".$prefix."_headlines WHERE
sitename='Linux.com'");
DROP TABLE:

the whole table nuke_priv_msgs is deleted from the database through the DROP TABLE command.

$db->sql_query("DROP TABLE ".$prefix."_priv_msgs");
ALTER TABLE:

the structure of the nuke_users table is modified through the ALTER TABLE command:

$db->sql_query("ALTER TABLE ".$user_prefix."_users CHANGE uname username
VARCHAR(25) NOT NULL");
CREATE TABLE:

a new table (nuke_bbforum_prune) is created through the CREATE TABLE command:

$db->sql_query("CREATE TABLE ".$prefix."_bbforum_prune (prune_id mediumint
(8) unsigned NOT NULL auto_increment, forum_id smallint(5) unsigned NOT NULL
default '0', prune_days tinyint(4) unsigned NOT NULL default '0', prune_freq tinyint
(4) unsigned NOT NULL default '0', PRIMARY KEY (prune_id), KEY forum_id
(forum_id))");

See Section 28.5 for the syntax of SQL code.

Notes

[1]

We will assume all prefixes, like $prefix and $user_prefix to be “nuke”.