function patch_database() { // sanity check. check that the version table exists. global $dbconfig, $db; $has_table = $db->getOne("SHOW TABLES LIKE '{$dbconfig['table_prefix']}version'"); if (!$has_table) { init_database(); } $last_patch = $db->getOne('SELECT ver_version FROM {{%version}}'); if (!isset($last_patch)) { // insert initial value $db->query('INSERT INTO {{%version}} SET ver_version=0'); $last_patch = 0; } $files = read_patches(__DIR__ . '/patches'); $addCount = 0; foreach ($files as $number => $file) { if ($number > $last_patch) { echo '* Applying patch: ', $number, ' (', basename($file), ")\n"; exec_sql_file($file); $db->query("UPDATE {{%version}} SET ver_version={$number}"); $addCount++; } } $version = max(array_keys($files)); if ($addCount == 0) { echo "* Your database is already up-to-date. Version {$version}\n"; } else { echo "* Your database is now up-to-date. Updated from {$last_patch} to {$version}\n"; } }
<?php if (!defined('THINK_PATH')) { exit; } header('Content-Type: text/html; charset=utf-8'); $sql_file = APP_PATH . '/User/Appinfo/install.sql'; $res = exec_sql_file($sql_file); if (!empty($res)) { echo $res['error_code']; echo '<br />'; echo $res['error_sql']; include_once APP_PATH . '/User/Appinfo/uninstall.php'; exit; }