|
From: FlorinCB <ory...@us...> - 2008-10-05 08:52:23
|
Update of /cvsroot/mxbb/core/install In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12036 Added Files: db_convert.php Log Message: fix --- NEW FILE: db_convert.php --- <?php /** * * @package MX-Publisher Core * @version $Id: db_convert.php,v 1.1 2008/10/05 08:47:58 orynider Exp $ * @copyright (c) 2002-2008 MX-Publisher Project Team * @based on tutorial by http://www.sveit.com * @link http://www.mx-publisher.com * */ // // Initialization // define('IN_PORTAL', true); define('IN_PHPBB', true); define('INSTALLING', true); $mx_root_path = '../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); $tplEx = @file_exists($mx_root_path.'install/templates/mx_install_header.html') ? 'html' : 'tpl'; define('INSTALLER_VERSION', '0.0.1'); define('INSTALLER_NAME', 'MX-Publisher-DB-Converter'); @ini_set( 'display_errors', '1' ); error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT); if( @file_exists($mx_root_path . "config.$phpEx") ) { include($mx_root_path . "config.$phpEx"); } // // Redirect for fresh MX-Publisher install // if( !defined('MX_INSTALLED') || (MX_INSTALLED === false) ) { header('Location: ' . $mx_root_path . 'install/mx_install.' . $phpEx); exit; } include_once($mx_root_path . "includes/db/" . $dbms . ".$phpEx"); // Load dbal and initiate class include_once($mx_root_path . "install/includes/functions_install.$phpEx"); $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { install_die("SQL Error: Could not connect to the database"); } unset($dbpasswd); switch ($db->sql_layer) { case 'mysql': case 'mysql4': case 'mysqli': $sql = 'SHOW TABLES'; break; case 'sqlite': $sql = 'SELECT name FROM sqlite_master WHERE type = "table"'; break; case 'mssql': case 'mssql_odbc': $sql = "SELECT name FROM sysobjects WHERE type='U'"; break; case 'postgres': $sql = 'SELECT relname FROM pg_stat_user_tables'; break; case 'firebird': $sql = 'SELECT rdb$relation_name FROM rdb$relations WHERE rdb$view_source is null AND rdb$system_flag = 0'; break; case 'oracle': $sql = 'SELECT table_name FROM USER_TABLES'; break; } if (!($result = $db->sql_query($sql))) { install_die('SQL Error: ' . 'Line: ' . __LINE__ . 'File: ' . __FILE__ . 'Query: ' . $sql); } // Loop through all tables in this database while ($row = $db->sql_fetchrow($result)) { $tables = array(); $tables[] = current($row); $db->sql_freeresult($result); $table = $tables[0]; $sql2 = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"; if ( !($result2 = $db->sql_query($sql2)) ) { install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql2); break; } print "$table changed to UTF-8 successfully.<br>\n"; // Now loop through all the fields within this table $sql3 = "SHOW COLUMNS FROM $table"; if ( !($result3 = $db->sql_query($sql3)) ) { install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); break; } while ( $row3 = $db->sql_fetchrow($result3) ) { $field_name = $row3[0]; $field_type = $row3[1]; // Change text based fields $skipped_field_types = array('char', 'text', 'blob', 'enum', 'set'); foreach ( $skipped_field_types as $type ) { if ( strpos($field_type, $type) !== false ) { $sql4 = "ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type CHARACTER SET utf8 COLLATE utf8_bin"; if ( !($result4 = $db->sql_query($sql4)) ) { install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql4); break 3; } print "---- $field_name changed to UTF-8 successfully.<br>\n"; } } } print "<hr>\n"; } // // Close our DB connection. // $db->sql_close(); ?> |