0 && $test <> 1007) { db_err( "stepBack", T_("A database error occurred: ") . (mysql_error()) ); } // db is now new or existing, create the db object connector to do the serious work $database = new database( $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix ); //Delete existing tables from a previous installation if found. Backup tables if requested. $database->setQuery( "SHOW TABLES FROM `$DBname`" ); $errors = array(); if ($tables = $database->loadResultArray()) { foreach ($tables as $table) { //Check for the existance of tables with the same prefix if (strpos( $table, $DBPrefix ) === 0) { //Check to see if the user requested a backup if ($DBBackup==1) { //if they requested a backup then replace the org table prefix with old_ $butable = str_replace( $DBPrefix, $BUPrefix, $table ); //if a prior backup table exists with the same name then drop it before the rename $database->setQuery( "DROP TABLE IF EXISTS `$butable`" ); $database->query(); if ($database->getErrorNum()) { $errors[$database->getQuery()] = $database->getErrorMsg(); } //Perform the actual table rename $database->setQuery( "RENAME TABLE `$table` TO `$butable`" ); $database->query(); if ($database->getErrorNum()) { $errors[$database->getQuery()] = $database->getErrorMsg(); } } else { //No backup was requested so just drop the original table $database->setQuery( "DROP TABLE IF EXISTS `$table`" ); $database->query(); if ($database->getErrorNum()) { $errors[$database->getQuery()] = $database->getErrorMsg(); } } } } //end foreach } //end if populate_db($DBname,$DBPrefix,'mambo.sql'); if ($DBSample) { populate_db($DBname,$DBPrefix,'sample_data.sql'); } $DBcreated = 1; } function db_err($step, $alert) { global $DBhostname,$DBuserName,$DBpassword,$DBDel,$DBname; echo "
\n"; //echo ""; echo ""; //this wasn't working exit(); } function populate_db($DBname, $DBPrefix, $sqlfile='mambo.sql') { global $errors; mysql_select_db($DBname); $mqr = @get_magic_quotes_runtime(); @set_magic_quotes_runtime(0); $query = fread(fopen("sql/".$sqlfile, "r"), filesize("sql/".$sqlfile)); @set_magic_quotes_runtime($mqr); $pieces = split_sql($query); for ($i=0; $i