diff --git a/lib/zdb/zdb.class.php b/lib/zdb/zdb.class.php index d2d4432738..9e59eb5fa1 100644 --- a/lib/zdb/zdb.class.php +++ b/lib/zdb/zdb.class.php @@ -48,11 +48,12 @@ class zdb /* Get all tables in database. */ $allTables = array(); - $stmt = $this->dbh->query('show tables'); - while($table = $stmt->fetch(PDO::FETCH_ASSOC)) + $stmt = $this->dbh->query("show full tables"); + while($table = $stmt->fetch(PDO::FETCH_ASSOC)) { - $table = current($table); - $allTables[$table] = $table; + $tableName = $table['Tables_in_zentao']; + $tableType = strtolower($table['Table_type']); + $allTables[$tableName] = $tableType == 'base table' ? 'table' : $tableType; } /* Dump all tables when tables is empty. */ @@ -75,15 +76,16 @@ class zdb /* Open this file. */ $fp = fopen($fileName, 'w'); fwrite($fp, "SET NAMES utf8;\n"); - foreach($tables as $table) + foreach($tables as $table => $tableType) { /* Check table exists. */ if(!isset($allTables[$table])) continue; /* Create sql code. */ - $backupSql = "DROP TABLE IF EXISTS `$table`;\n"; - $backupSql .= $this->getSchemaSQL($table); + $backupSql = "DROP " . strtoupper($tableType) . " IF EXISTS `$table`;\n"; + $backupSql .= $this->getSchemaSQL($table, $tableType); fwrite($fp, $backupSql); + if($tableType != 'table') continue; $rows = $this->dbh->query("select * from `$table`"); while($row = $rows->fetch(PDO::FETCH_ASSOC)) @@ -186,9 +188,10 @@ class zdb * @access public * @return string */ - public function getSchemaSQL($table) + public function getSchemaSQL($table, $type = 'table') { - $createSql = $this->dbh->query("show create table `$table`")->fetch(PDO::FETCH_ASSOC); - return $createSql['Create Table'] . ";\n"; + $sql = "SHOW CREATE $type `$table`"; + $createSql = $this->dbh->query($sql)->fetch(PDO::FETCH_ASSOC); + return $createSql['Create ' . ucfirst($type)] . ";\n"; } } diff --git a/module/admin/control.php b/module/admin/control.php index bd5d3fc771..c5baabaf55 100644 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -116,10 +116,10 @@ class admin extends control */ public function checkDB() { - $tables = $this->dbh->query('SHOW TABLES')->fetchAll(); + $tables = $this->dbh->query("show full tables where Table_Type != 'VIEW'")->fetchAll(PDO::FETCH_ASSOC); foreach($tables as $table) { - $tableName = current((array)$table); + $tableName = current($table); $result = $this->dbh->query("REPAIR TABLE $tableName")->fetch(); echo "Repairing TABLE: " . $result->Table . "\t" . $result->Msg_type . ":" . $result->Msg_text . "\n"; }