
28.02.2009, 01:28
|
|
Новичок
Регистрация: 11.12.2007
Сообщений: 12
С нами:
9692436
Репутация:
3
|
|
Привет всем. Подскажите пожалуйста как сменить кодировку БД с UTF-8 на win1251. Я раздобыл скриптик, но как его настроить хз.
Код:
<?php $db = mysqli_connect('localhost','username','password', 'db'); if(mysqli_connect_errno()) { echo "Cannot connect to the database - incorrect details"; } $sql = 'SHOW TABLES'; if ( !( $result = $db->query( $sql ) ) ) { echo '<span style="color: red;">Get SHOW TABLE - SQL Error: <br>' . "</span>\n"; } while ( $tables = $result->fetch_row() ) { echo $tables[0]; # Loop through all tables in this database $table = $tables[key($tables)]; if ( !( $result2 = $db->query("ALTER TABLE ".$table." COLLATE utf8_general_ci") ) ) { echo '<span style="color: red;">UTF SET - SQL Error: <br>' . "</span>\n"; break; } print "$table changed to UTF-8 successfully.<br>\n"; # Now loop through all the fields within this table if ( !($result2 = $db->query("SHOW COLUMNS FROM ".$table) ) ) { echo '<span style="color: red;">Get Table Columns Query - SQL Error: <br>' . "</span>\n"; break; } while ( $column = $result2->fetch_assoc() ) { $field_name = $column['Field']; $field_type = $column['Type']; # Change text based fields $skipped_field_types = array('char', 'text', '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_general_ci"; $result4 = $db->query($sql4); echo "---- $field_name changed to UTF-8 successfully.<br>\n"; } } } echo "<hr>\n"; } $result->free(); $result2->free(); $result4->free(); ?>
Что где изменить надо? Подскажите пожалуйста?
|
|
|