PHP MyISAM > InnoDB 上的语法错误:需要“}”

PHP Syntax error on MyISAM > InnoDB: expecting '}'

当执行某人创建的用于将 MyISAM 转换为 InnoDB 的脚本 I found online 时,它会抛出一个语法错误,我试图找出并随机放入(这不是 [=25= 的深度) ] 程序员。)有人好心帮助 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']]}'";