简体   繁体   English

MyISAM> InnoDB上的PHP语法错误:期望'}'

[英]PHP Syntax error on MyISAM > InnoDB: expecting '}'

When executing a script I found online that someone created to convert MyISAM to InnoDB it throws a syntax error that I've tried to figure out and put in randomly (Not this in depth of a PHP programmer at all.) Someone kindly help a python programmer? 执行脚本时, 我在网上发现有人创建了将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

Lines 40-53 : 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 

Overall Script 整体剧本

<?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);

you didn't close brace in this line 41, 您没有在第41行中关闭括号,

$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]'";

try like this 这样尝试

 $sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]}'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 的PHP-语法错误,意外的&#39;(&#39;,期待&#39;)&#39; - php - syntax error, unexpected '(', expecting ')' 从myISAM转换为innodb的MySQL错误 - Mysql error with converting from myISAM to innodb 解析错误:语法错误,意外的 &#39;[&#39;,期待 &#39;)&#39; php - Parse error: syntax error, unexpected '[', expecting ')' php PHP解析错误:语法错误,意外的“:”,期待“;” 或者 &#39;{&#39; - PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' 语法错误,意外&#39;。&#39;,在config.php中期待&#39;]&#39; - syntax error, unexpected '.', expecting ']' in config.php 解析错误:语法错误,意外的&#39;[&#39;,期望&#39;)&#39;,可能是PHP版本问题 - Parse error: syntax error, unexpected '[', expecting ')', possibly PHP version issue Wordpress插件PHP解析错误:语法错误,意外的“ {”,预期为“)” - Wordpress plugin PHP Parse error: syntax error, unexpected '{', expecting ')' 解析错误:语法错误,意外的&#39;;&#39;,期望的是&#39;)&#39;(Wordpress functions.php) - Parse error: syntax error, unexpected ';', expecting ')' (Wordpress functions.php) PHP 版本 4:: 解析错误:语法错误,意外 '=',期待 ')' - PHP version 4 :: Parse error: syntax error, unexpected '=', expecting ')' 语法错误,意外的&#39;[&#39;,期望&#39;)&#39; - Syntax error, unexpected '[', expecting ')'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM