php time microtime true db vspomni login vspomni passw host vspomni ru

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
<?php
$time = microtime(true);
$db = 'vspomni';
$login = 'vspomni';
$passw = '';
$host = 'vspomni.ru';
$res = mysql_connect($host, $login, $passw);
mysql_select_db($db);
mysql_query('SET NAMES utf8;');
$rs = mysql_query('SHOW TABLES;');
print mysql_error(); //the notorious 'command out of synch' message :(
while (($row=mysql_fetch_assoc($rs))!==false) {
$time1 = microtime(true);
//print $row['Tables_in_vspomni2']."\n";
$table_name = $row['Tables_in_'.$db];
$query = 'SHOW CREATE TABLE '.$table_name;
$row_create = mysql_query($query);
print mysql_error();
$row1 = mysql_fetch_assoc($row_create);
if (strpos($row1['Create Table'], 'DEFAULT CHARSET=utf8') !== false)
{
print 'Table '.$table_name.' — skipped'."\n";
continue;
}
$create_table_scheme = str_ireplace('cp1251', 'utf8', $row1['Create Table']); // CREATE TABLE SCHEME
$create_table_scheme = str_ireplace('ENGINE=InnoDB', 'MyISAM', $create_table_scheme);
$create_table_scheme .= ' COLLATE utf8_bin';
//print $create_table_scheme;
//continue;
$query = 'RENAME TABLE '.$table_name.' TO '.$table_name.'_tmp_export'; // RENAME TABLE;
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
$query = $create_table_scheme;
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
$query = 'ALTER TABLE '.$table_name.' DISABLE KEYS';
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
$query = 'INSERT INTO '.$table_name.' SELECT * FROM '.$table_name.'_tmp_export';
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
$query = 'DROP TABLE '.$table_name.'_tmp_export';
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
$time3 = microtime(true);
$query = 'ALTER TABLE '.$table_name.' ENABLE KEYS';
mysql_query($query);
$error = mysql_error();
if (strlen($error) > 0)
{
print $error.' — LINE '.__LINE__."\n";
break;
}
print 'Enable keys to '.$table_name.'. time -'.(microtime(true) — $time3)."\n";
print 'converted '.$table_name.'. time — '.(microtime(true) — $time1)."\n\n";
}
mysql_free_result($rs);
print 'done. total time -'.(microtime(true) — $time);
?>