. */ error_reporting(E_ALL); ini_set('display_errors', 1); require(__DIR__ . '/../conf.php'); function lower_version($that, $new) { $that = explode('.', $that); $new = explode('.', $new); while (count($that) < count($new)) $that[] = 0; while (count($new) < count($that)) $new[] = 0; for ($i = 0; $i < count($new); $i++) { if ($new[$i] > $that[$i]) { return true; } elseif ($new[$i] < $that[$i]) { return false; } } return false; } if (isset($_GET['upgrade'])) { if (lower_version($_GET['upgrade'], '0.1')) { try { $_pdo->query("ALTER TABLE `".Constants::db_prefix."assignment` CHANGE `hours` `hours` FLOAT UNSIGNED NOT NULL"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.2.2')) { try { $_pdo->query("ALTER TABLE `".Constants::db_prefix."assignment` DROP FOREIGN KEY `assignment_ibfk_1`"); $_pdo->query("ALTER TABLE `".Constants::db_prefix."assignment` ADD CONSTRAINT `assignment_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".Constants::db_prefix."offer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.3')) { try { $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."discount` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `offerId` smallint(5) unsigned NOT NULL, `title` tinytext NOT NULL, `description` text NOT NULL, `value` float unsigned NOT NULL, `VAT_percentage` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $_pdo->query("ALTER TABLE `".Constants::db_prefix."discount` ADD CONSTRAINT `discount_ibfk_1` FOREIGN KEY (`offerId`) REFERENCES `".Constants::db_prefix."offer` (`id`);"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.4')) { try { $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."user` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `password` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.4.2')) { try { $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."payment` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `offerId` smallint(5) unsigned NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $offers = $_pdo->query("SELECT `id`,`payment_received` FROM `".Constants::db_prefix."offer` WHERE `payment_received` IS NOT NULL"); $offers = $offers->fetchAll(PDO::FETCH_ASSOC); foreach ($offers as $offer) { $stmt = $_pdo->prepare("INSERT IGNORE INTO `".Constants::db_prefix."payment` (`offerId`,`date`) VALUES (?,?)"); $stmt->execute([$offer['id'], $offer['payment_received']]); } $_pdo->query("ALTER TABLE `".Constants::db_prefix."offer` DROP `payment_received`;"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.5')) { try { $_pdo->query("ALTER TABLE `".Constants::db_prefix."offer` ADD `payment_key` VARCHAR(63) DEFAULT NULL;"); $_pdo->query("ALTER TABLE `".Constants::db_prefix."payment` ADD `braintree_id` VARCHAR(36) DEFAULT NULL, ADD `braintree_status` VARCHAR (63) NULL DEFAULT NULL;"); $_pdo->query("CREATE UNIQUE INDEX `payment_uniq_1` ON `".Constants::db_prefix."payment` (`offerId`);"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.5.1')) { try { $_pdo->query("ALTER TABLE `".Constants::db_prefix."file` ADD `secret_key` VARCHAR(63) DEFAULT NULL;"); $files = $_pdo->query("SELECT `id` FROM `".Constants::db_prefix."file` WHERE `secret_key` IS NULL;"); $stmt = $_pdo->prepare("UPDATE `".Constants::db_prefix."file` SET `secret_key`=? WHERE `id`=?"); foreach ($files->fetchAll(PDO::FETCH_ASSOC) as $file) { $key = preg_replace('/[^\w]+/', '', base64_encode(openssl_random_pseudo_bytes(45))); $stmt->execute([$key, $file['id']]); } } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } if (lower_version($_GET['upgrade'], '0.5.2')) { try { $_pdo->query("CREATE TABLE IF NOT EXISTS `".Constants::db_prefix."mail` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `contactId` smallint(5) unsigned NOT NULL, `offerId` smallint(5) unsigned DEFAULT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `subject` varchar(100) NOT NULL, PRIMARY KEY (`id`), KEY `contactId` (`contactId`), KEY `offerId` (`offerId`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); $_pdo->query("ALTER TABLE `".Constants::db_prefix."mail` ADD CONSTRAINT `mail_ibfk_1` FOREIGN KEY (`contactId`) REFERENCES `".Constants::db_prefix."contact` (`id`) ON UPDATE CASCADE, ADD CONSTRAINT `mail_ibfk_2` FOREIGN KEY (`offerId`) REFERENCES `".Constants::db_prefix."offer` (`id`) ON UPDATE CASCADE;"); } catch (PDOException $e) { echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); } } echo "
All done."; } ?>

You're going to upgrade to version . What was your old version number?