db_version; if(!$dbdbversion) { echo "Could not get current 'Evaluations' db version. Is the plug-in properly installed?\n"; exit; } if($dbcodeversion && $dbdbversion) { //lets see if they match if($dbcodeversion == $dbdbversion) { echo "DB and CODE for 'Evaluations' are all up-to-date. Version: $dbdbversion\n"; exit; } else if($dbcodeversion<$dbdbversion) { echo "ERROR: dbcodeversion$dbdbversion) { echo "DB update requirements detected
"; echo "Current 'Evaluations' DB Version: $dbdbversion
"; echo "Current 'Evaluations' CODE Version: $dbcodeversion
"; echo "Updating database from $dbdbversion to $dbcodeversion
"; for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++) { if(file_exists("db.eval.update.$ver.sql")) { echo "db.eval.update.$ver.sql detected - running..."; $exit_code = 0; // assume no errors for now $filename = 'db.eval.update.'.$ver.'.sql'; // Temporary variable, used to store current query $templine = ''; // Read in entire file $lines = file($filename); // Loop through each line foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') continue; // Add this line to the current segment $templine .= $line; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1, 1) == ';') { // Perform the query if(!mysql_query($templine)){ echo('
Error performing query!
'.$templine.'
mysqlerror: '.mysql_error().'

'); $error_count += 1; $exit_code = -1; // do we bail out here or keep going? keep going for now, get all errors } // Reset temp variable to empty $templine = ''; } } if($exit_code != 0) { /* mysql failed!, what now? */ $error_count += 1; echo "
ERROR in db_update: Failed to execute query(s) without error!
"; } else{ echo " Done!
"; } } else { echo "Version $ver SQL update file not found - skipping over\n"; } } echo "
All done - updating Evaluations' new DB version to $dbcodeversion\n"; if ($error_count == 0 ){ mysql_query("UPDATE eval_config SET db_version='$dbcodeversion'"); } } } else { echo "ERROR: dbcodeversion and dbdbversion are not defined\n"; } ?>