143a144,145 > > if (is_array($tables) { 145,470c147,474 < foreach ($tables as $t) { < < if ($format == "SQL") { < < if ($conn->getAdapter() == "mysql") < $structureSQL = $conn->query("SHOW FULL FIELDS FROM `$t`"); < else < $structureSQL = $conn->describeTable($t); < < $tableEngine = ""; < $tableCharset = ""; < $autoIncrement = ""; < < if (isset($exportStructure)) { < < if ($conn->isResultSet($structureSQL)) { < < if ($conn->getAdapter() == "mysql") { < < $outputBuffer .= "CREATE TABLE `$t` ("; < < $infoSql = $conn->query("SHOW TABLE STATUS LIKE '$t'"); < < if ($conn->isResultSet($infoSql) == 1) { < < $infoRow = $conn->fetchAssoc($infoSql); < < $tableEngine = (array_key_exists("Type", $infoRow)) ? $infoRow['Type'] : $infoRow['Engine']; < < if (array_key_exists('Collation', $infoRow) && isset($collationList)) { < $tableCharset = $collationList[$infoRow['Collation']]; < } < < if (array_key_exists('Auto_increment', $infoRow)) < { < $autoIncrement = $infoRow['Auto_increment']; < } < } < < } else if ($conn->getAdapter() == "sqlite") { < < $outputBuffer .= "CREATE TABLE '$t' ("; < } < < $first = true; < < if ($conn->getAdapter() == "mysql") { < < while ($structureRow = $conn->fetchassoc($structureSQL)) { < < if (!$first) < $outputBuffer .= ","; < < $outputBuffer .= "\r\n `" . $structureRow['Field'] . "` " . $structureRow['Type']; < < if (isset($collationList) && isset($structureRow['Collation']) && $structureRow['Collation'] != "NULL" && !is_null($structureRow['Collation'])) { < if ($collationList[$structureRow['Collation']] != $tableCharset) { < $outputBuffer .= " CHARSET " . $collationList[$structureRow['Collation']]; < } < } < < if (isset($structureRow['Null']) && $structureRow['Null'] != "YES") < $outputBuffer .= " not null"; < < if (isset($structureRow['Default']) && $structureRow['Default'] == "CURRENT_TIMESTAMP") { < $outputBuffer .= " default CURRENT_TIMESTAMP"; < } else if (isset($structureRow['Default']) && $structureRow['Default'] != "") { < $outputBuffer .= " default '" . $structureRow['Default'] . "'"; < } < < if (isset($structureRow['Extra']) && $structureRow['Extra'] != "") < $outputBuffer .= " " . $structureRow['Extra']; < < $first = false; < } < < } else if ($conn->getAdapter() == "sqlite") { < < foreach ($structureSQL as $structureRow) { < < if (!$first) < $outputBuffer .= ","; < < $outputBuffer .= "\r\n " . $structureRow[0] . " " . $structureRow[1]; < < $first = false; < } < < } < < // dont forget about the keys < if ($conn->getAdapter() == "mysql") { < $keySQL = $conn->query("SHOW INDEX FROM `$t`"); < < if ($conn->isResultSet($keySQL)) { < $currentKey = ""; < while ($keyRow = $conn->fetchAssoc($keySQL)) { < // if this is the start of a key < if ($keyRow['Key_name'] != $currentKey) { < // finish off the last key first, if necessary < if ($currentKey != "") < $outputBuffer .= ")"; < < if ($keyRow['Key_name'] == "PRIMARY") < $outputBuffer .= ",\r\n PRIMARY KEY ("; < elseif ($keyRow['Non_unique'] == "0") < $outputBuffer .= ",\r\n UNIQUE KEY ("; < else < $outputBuffer .= ",\r\n KEY `" . $keyRow['Key_name'] . "` ("; < < $outputBuffer .= "`" . $keyRow['Column_name'] . "`"; < } else { < $outputBuffer .= ",`" . $keyRow['Column_name'] . "`"; < } < < $currentKey = $keyRow['Key_name']; < } < < if (isset($currentKey) && $currentKey != "") < $outputBuffer .= ")"; < } < } < < $outputBuffer .= "\r\n)"; < < if ($conn->getAdapter() == "mysql") { < if ($tableEngine) { < $outputBuffer .= ' ENGINE=' . $tableEngine; < } < < if ($tableCharset) { < $outputBuffer .= ' DEFAULT CHARSET=' . $tableCharset; < } < < if ($autoIncrement) < { < $outputBuffer .= ' AUTO_INCREMENT=' . $autoIncrement; < } < } < < $outputBuffer .= ";\r\n\r\n"; < } < } < < if ($conn->getAdapter() == "mysql") < $structureSQL = $conn->query("SHOW FULL FIELDS FROM `$t`"); < else < $structureSQL = $conn->describeTable($t); < < if (isset($exportData)) { < < $columnList = array(); < < if ($conn->getAdapter() == "mysql") { < < $dataSQL = $conn->query("SELECT * FROM `$t`"); < < // put the column names in an array < if ($conn->isResultSet($structureSQL)) { < while ($structureRow = $conn->fetchAssoc($structureSQL)) { < $columnList[] = $structureRow['Field']; < $type[] = $structureRow['Type']; < } < } < < $columnImplosion = implode("`, `", $columnList); < < if ($conn->isResultSet($dataSQL)) { < < if ($insertType == "COMPACT") < $outputBuffer .= "INSERT INTO `$t` (`$columnImplosion`) VALUES \r\n"; < < $firstLine = true; < < while ($dataRow = $conn->fetchAssoc($dataSQL)) { < < if ($insertType == "COMPLETE") { < $outputBuffer .= "INSERT INTO `$t` (`$columnImplosion`) VALUES "; < } else { < if (!$firstLine) < $outputBuffer .= ",\r\n"; < } < < $outputBuffer .= "("; < < $first = true; < < for ($i=0; $iescapeString($currentData) . "'"; < } < < $first = false; < } < < $outputBuffer .= ")"; < < if ($insertType == "COMPLETE") < $outputBuffer .= ";\r\n"; < < $firstLine = false; < < } < < if ($insertType == "COMPACT") < $outputBuffer .= ";\r\n"; < < } else { < $outputBuffer .= "-- [" . sprintf(__("Table `%s` is empty"), $t) . "]\r\n"; < } < < } else if ($conn->getAdapter() == "sqlite") { < < $dataSQL = $conn->query("SELECT * FROM '$t'"); < < // put the column names in an array < if ($conn->isResultSet($structureSQL)) { < foreach ($structureSQL as $structureRow) { < $columnList[] = $structureRow[0]; < $type[] = $structureRow[1]; < } < } < < $columnImplosion = implode("', '", $columnList); < < if ($conn->isResultSet($dataSQL)) { < < $firstLine = true; < < while ($dataRow = $conn->fetchAssoc($dataSQL)) { < < $outputBuffer .= "INSERT INTO '$t' ('$columnImplosion') VALUES ("; < < $first = true; < < for ($i=0; $iescapeString($currentData) . "'"; < < $first = false; < } < < $outputBuffer .= ");\r\n"; < < $firstLine = false; < < } < < } else { < $outputBuffer .= "-- [" . sprintf(__("Table `%s` is empty"), $t) . "]\r\n"; < } < < } < } < < $outputBuffer .= "\r\n"; < < } else if ($format == "CSV") { < < if (isset($printFieldnames)) { < $structureSQL = $conn->describeTable($t); < < if ($conn->isResultSet($structureSQL)) { < $first = true; < < if ($conn->getAdapter() == "mysql") { < < while ($structureRow = $conn->fetchArray($structureSQL)) { < if (!$first) < $outputBuffer .= $delimiter; < < $outputBuffer .= "\"" . $structureRow[0] . "\""; < < $first = false; < } < < } else if ($conn->getAdapter() == "sqlite") { < < foreach ($structureSQL as $structureRow) { < if (!$first) < $outputBuffer .= $delimiter; < < $outputBuffer .= "\"" . $structureRow[0] . "\""; < < $first = false; < } < < } < < $outputBuffer .= "\r\n"; < } < } < < if ($conn->getAdapter() == "mysql") { < $dataSQL = $conn->query("SELECT * FROM `$t`"); < } else if ($conn->getAdapter() == "sqlite") { < $dataSQL = $conn->query("SELECT * FROM '$t'"); < } < < if ($conn->isResultSet($dataSQL)) { < while ($dataRow = $conn->fetchArray($dataSQL)) { < $data = array(); < foreach ($dataRow as $each) { < $data[] = "\"" . formatDataForCSV($each) . "\""; < } < < $dataLine = implode($delimiter, $data); < < $outputBuffer .= $dataLine . "\r\n"; < } < } < < } < < } --- > foreach ($tables as $t) { > > if ($format == "SQL") { > > if ($conn->getAdapter() == "mysql") > $structureSQL = $conn->query("SHOW FULL FIELDS FROM `$t`"); > else > $structureSQL = $conn->describeTable($t); > > $tableEngine = ""; > $tableCharset = ""; > $autoIncrement = ""; > > if (isset($exportStructure)) { > > if ($conn->isResultSet($structureSQL)) { > > if ($conn->getAdapter() == "mysql") { > > $outputBuffer .= "CREATE TABLE `$t` ("; > > $infoSql = $conn->query("SHOW TABLE STATUS LIKE '$t'"); > > if ($conn->isResultSet($infoSql) == 1) { > > $infoRow = $conn->fetchAssoc($infoSql); > > $tableEngine = (array_key_exists("Type", $infoRow)) ? $infoRow['Type'] : $infoRow['Engine']; > > if (array_key_exists('Collation', $infoRow) && isset($collationList)) { > $tableCharset = $collationList[$infoRow['Collation']]; > } > > if (array_key_exists('Auto_increment', $infoRow)) > { > $autoIncrement = $infoRow['Auto_increment']; > } > } > > } else if ($conn->getAdapter() == "sqlite") { > > $outputBuffer .= "CREATE TABLE '$t' ("; > } > > $first = true; > > if ($conn->getAdapter() == "mysql") { > > while ($structureRow = $conn->fetchassoc($structureSQL)) { > > if (!$first) > $outputBuffer .= ","; > > $outputBuffer .= "\r\n `" . $structureRow['Field'] . "` " . $structureRow['Type']; > > if (isset($collationList) && isset($structureRow['Collation']) && $structureRow['Collation'] != "NULL" && !is_null($structureRow['Collation'])) { > if ($collationList[$structureRow['Collation']] != $tableCharset) { > $outputBuffer .= " CHARSET " . $collationList[$structureRow['Collation']]; > } > } > > if (isset($structureRow['Null']) && $structureRow['Null'] != "YES") > $outputBuffer .= " not null"; > > if (isset($structureRow['Default']) && $structureRow['Default'] == "CURRENT_TIMESTAMP") { > $outputBuffer .= " default CURRENT_TIMESTAMP"; > } else if (isset($structureRow['Default']) && $structureRow['Default'] != "") { > $outputBuffer .= " default '" . $structureRow['Default'] . "'"; > } > > if (isset($structureRow['Extra']) && $structureRow['Extra'] != "") > $outputBuffer .= " " . $structureRow['Extra']; > > $first = false; > } > > } else if ($conn->getAdapter() == "sqlite") { > > foreach ($structureSQL as $structureRow) { > > if (!$first) > $outputBuffer .= ","; > > $outputBuffer .= "\r\n " . $structureRow[0] . " " . $structureRow[1]; > > $first = false; > } > > } > > // dont forget about the keys > if ($conn->getAdapter() == "mysql") { > $keySQL = $conn->query("SHOW INDEX FROM `$t`"); > > if ($conn->isResultSet($keySQL)) { > $currentKey = ""; > while ($keyRow = $conn->fetchAssoc($keySQL)) { > // if this is the start of a key > if ($keyRow['Key_name'] != $currentKey) { > // finish off the last key first, if necessary > if ($currentKey != "") > $outputBuffer .= ")"; > > if ($keyRow['Key_name'] == "PRIMARY") > $outputBuffer .= ",\r\n PRIMARY KEY ("; > elseif ($keyRow['Non_unique'] == "0") > $outputBuffer .= ",\r\n UNIQUE KEY ("; > else > $outputBuffer .= ",\r\n KEY `" . $keyRow['Key_name'] . "` ("; > > $outputBuffer .= "`" . $keyRow['Column_name'] . "`"; > } else { > $outputBuffer .= ",`" . $keyRow['Column_name'] . "`"; > } > > $currentKey = $keyRow['Key_name']; > } > > if (isset($currentKey) && $currentKey != "") > $outputBuffer .= ")"; > } > } > > $outputBuffer .= "\r\n)"; > > if ($conn->getAdapter() == "mysql") { > if ($tableEngine) { > $outputBuffer .= ' ENGINE=' . $tableEngine; > } > > if ($tableCharset) { > $outputBuffer .= ' DEFAULT CHARSET=' . $tableCharset; > } > > if ($autoIncrement) > { > $outputBuffer .= ' AUTO_INCREMENT=' . $autoIncrement; > } > } > > $outputBuffer .= ";\r\n\r\n"; > } > } > > if ($conn->getAdapter() == "mysql") > $structureSQL = $conn->query("SHOW FULL FIELDS FROM `$t`"); > else > $structureSQL = $conn->describeTable($t); > > if (isset($exportData)) { > > $columnList = array(); > > if ($conn->getAdapter() == "mysql") { > > $dataSQL = $conn->query("SELECT * FROM `$t`"); > > // put the column names in an array > if ($conn->isResultSet($structureSQL)) { > while ($structureRow = $conn->fetchAssoc($structureSQL)) { > $columnList[] = $structureRow['Field']; > $type[] = $structureRow['Type']; > } > } > > $columnImplosion = implode("`, `", $columnList); > > if ($conn->isResultSet($dataSQL)) { > > if ($insertType == "COMPACT") > $outputBuffer .= "INSERT INTO `$t` (`$columnImplosion`) VALUES \r\n"; > > $firstLine = true; > > while ($dataRow = $conn->fetchAssoc($dataSQL)) { > > if ($insertType == "COMPLETE") { > $outputBuffer .= "INSERT INTO `$t` (`$columnImplosion`) VALUES "; > } else { > if (!$firstLine) > $outputBuffer .= ",\r\n"; > } > > $outputBuffer .= "("; > > $first = true; > > for ($i=0; $i if (!$first) > $outputBuffer .= ", "; > > $currentData = $dataRow[$columnList[$i]]; > > if (isset($type) && $currentData && ((isset($binaryDTs) && in_array($type[$i], $binaryDTs)) || stristr($type[$i], "binary") !== false)) { > $outputBuffer .= "0x" . bin2hex($currentData); > } else { > $outputBuffer .= "'" . $conn->escapeString($currentData) . "'"; > } > > $first = false; > } > > $outputBuffer .= ")"; > > if ($insertType == "COMPLETE") > $outputBuffer .= ";\r\n"; > > $firstLine = false; > > } > > if ($insertType == "COMPACT") > $outputBuffer .= ";\r\n"; > > } else { > $outputBuffer .= "-- [" . sprintf(__("Table `%s` is empty"), $t) . "]\r\n"; > } > > } else if ($conn->getAdapter() == "sqlite") { > > $dataSQL = $conn->query("SELECT * FROM '$t'"); > > // put the column names in an array > if ($conn->isResultSet($structureSQL)) { > foreach ($structureSQL as $structureRow) { > $columnList[] = $structureRow[0]; > $type[] = $structureRow[1]; > } > } > > $columnImplosion = implode("', '", $columnList); > > if ($conn->isResultSet($dataSQL)) { > > $firstLine = true; > > while ($dataRow = $conn->fetchAssoc($dataSQL)) { > > $outputBuffer .= "INSERT INTO '$t' ('$columnImplosion') VALUES ("; > > $first = true; > > for ($i=0; $i if (!$first) > $outputBuffer .= ", "; > > $currentData = $dataRow[$columnList[$i]]; > > $outputBuffer .= "'" . $conn->escapeString($currentData) . "'"; > > $first = false; > } > > $outputBuffer .= ");\r\n"; > > $firstLine = false; > > } > > } else { > $outputBuffer .= "-- [" . sprintf(__("Table `%s` is empty"), $t) . "]\r\n"; > } > > } > } > > $outputBuffer .= "\r\n"; > > } else if ($format == "CSV") { > > if (isset($printFieldnames)) { > $structureSQL = $conn->describeTable($t); > > if ($conn->isResultSet($structureSQL)) { > $first = true; > > if ($conn->getAdapter() == "mysql") { > > while ($structureRow = $conn->fetchArray($structureSQL)) { > if (!$first) > $outputBuffer .= $delimiter; > > $outputBuffer .= "\"" . $structureRow[0] . "\""; > > $first = false; > } > > } else if ($conn->getAdapter() == "sqlite") { > > foreach ($structureSQL as $structureRow) { > if (!$first) > $outputBuffer .= $delimiter; > > $outputBuffer .= "\"" . $structureRow[0] . "\""; > > $first = false; > } > > } > > $outputBuffer .= "\r\n"; > } > } > > if ($conn->getAdapter() == "mysql") { > $dataSQL = $conn->query("SELECT * FROM `$t`"); > } else if ($conn->getAdapter() == "sqlite") { > $dataSQL = $conn->query("SELECT * FROM '$t'"); > } > > if ($conn->isResultSet($dataSQL)) { > while ($dataRow = $conn->fetchArray($dataSQL)) { > $data = array(); > foreach ($dataRow as $each) { > $data[] = "\"" . formatDataForCSV($each) . "\""; > } > > $dataLine = implode($delimiter, $data); > > $outputBuffer .= $dataLine . "\r\n"; > } > } > > } > > } > > }