function minRequiredVersion($db, $minVersion) { if (checkIfTableExists($db, "settings_<myname>")) { $row = $db->queryRow("SELECT * FROM settings_<myname> WHERE name = ?", 'version'); if ($row !== null) { global $version; if (version_compare(normalizeVersion($version), normalizeVersion($minVersion), '<')) { throw new Exception("Current required version is too old; you must upgrade to version {$minVersion} first before upgrading to {$version}"); } } } }
function checkIfColumnExists($db, $table, $column) { // If the table doesn't exist, return true since the table will be created with the correct column. if (checkIfTableExists($db, $table) == false) { return true; } // Else if the table exists but the column doesn't, return false so the table will be updated with the correct column. try { $data = $db->query("SELECT {$column} FROM {$table}"); } catch (SQLException $e) { return false; } // Else return true because both the table and the column exist. return true; }