При выполнении скрипта Я нашел в Интернете что кто-то создал, чтобы преобразовать MyISAM в InnoDB, он выдает синтаксическую ошибку, которую я пытался выяснить и вставил случайным образом (совсем не так глубоко в PHP-программисте.) Кто-то любезно помог бы программисту на python?
[root@server~]# php cli-mysql-to-innodb.php
PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '}' in /root/cli-mysql-to-innodb.php on line 44
Линии 40-53:
40 while ($row= $results->fetch_assoc()) {
41 $sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]'";
42 $thisTable = $mysqli->query($sql)->fetch_assoc();
43
44 if ($thisTable['Engine']==='MyISAM') {
45 $sql = "alter table " . $row['Tables_in_' . $db['database']]. " ENGINE = InnoDB;";
46 echo "Changing {$row['Tables_in_' . $db['database']]} from {$thisTable['Engine']} to InnoDB.\n";
47 $mysqli->query($sql);}
48 } else {
49 echo $row['Tables_in_' . $db['database']] . ' is of the Engine Type ' . $thisTable['Engine'] . ".\n";
50 echo "Not changing to InnoDB.\n\n";
51 }
52 }
53
Общий сценарий
<?php
/*
* Use this version if you are NOT a Pantheon customer.
*/
$db = array();
/*
* Change these to match your database connection information
*/
$db['host'] = "localhost";
$db['port'] = "3306";
$db['user'] = "";
$db['password'] = "";
$db['database'] = "";
/*
* DO NOT CHANGE ANYTHING BELOW THIS LINE
* Unless you know what you are doing. :)
*/
$db['connectString'] = $db['host'];
if (isset($db['port']) && (int)$db['port']==$db['port']) {
$db['connectString'] .= ":" . $db['port'];
}
$mysqli = @new mysqli($db['connectString'], $db['user'], $db['password'], $db['database']);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."\n";
die(1);
}
$results = $mysqli->query("show tables;");
if ($results===false or $mysqli->connect_errno) {
echo "MySQL error: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."\n";
die(2);
}
while ($row= $results->fetch_assoc()) {
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]'";
$thisTable = $mysqli->query($sql)->fetch_assoc();
if ($thisTable['Engine']==='MyISAM') {
$sql = "alter table " . $row['Tables_in_' . $db['database']]. " ENGINE = InnoDB;";
echo "Changing {$row['Tables_in_' . $db['database']]} from {$thisTable['Engine']} to InnoDB.\n";
$mysqli->query($sql);
} else {
echo $row['Tables_in_' . $db['database']] . ' is of the Engine Type ' . $thisTable['Engine'] . ".\n";
echo "Not changing to InnoDB.\n\n";
}
}
die(0);
вы не закрыли скобку в этой строке 41,
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]'";
попробуй вот так
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]}'";
Других решений пока нет …