[英]PHP Syntax error on MyISAM > InnoDB: expecting '}'
执行脚本时, 我在网上发现有人创建了将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']]}'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.