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?
[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 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,
$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']]}'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.