本文整理汇总了PHP中rex_sql::showCreateTable方法的典型用法代码示例。如果您正苦于以下问题:PHP rex_sql::showCreateTable方法的具体用法?PHP rex_sql::showCreateTable怎么用?PHP rex_sql::showCreateTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rex_sql
的用法示例。
在下文中一共展示了rex_sql::showCreateTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportDb
/**
* Erstellt einen SQL Dump, der die aktuellen Datebankstruktur darstellt.
* Dieser wird in der Datei $filename gespeichert.
*
* @param string $filename
* @param array $tables
*
* @return bool TRUE wenn ein Dump erstellt wurde, sonst FALSE
*/
public static function exportDb($filename, array $tables = null)
{
$fp = @fopen($filename, 'w');
if (!$fp) {
return false;
}
$sql = rex_sql::factory();
$nl = "\n";
$insertSize = 5000;
// ----- EXTENSION POINT
rex_extension::registerPoint(new rex_extension_point('BACKUP_BEFORE_DB_EXPORT'));
// Versionsstempel hinzufügen
fwrite($fp, '## Redaxo Database Dump Version ' . rex::getVersion('%s') . $nl);
fwrite($fp, '## Prefix ' . rex::getTablePrefix() . $nl);
//fwrite($fp, '## charset '.rex_i18n::msg('htmlcharset').$nl.$nl);
fwrite($fp, '## charset utf-8' . $nl . $nl);
// fwrite($fp, '/*!40110 START TRANSACTION; */'.$nl);
if (is_null($tables)) {
$tables = [];
foreach (rex_sql::showTables(1, rex::getTablePrefix()) as $table) {
if ($table != rex::getTable('user') && substr($table, 0, strlen(rex::getTablePrefix() . rex::getTempPrefix())) != rex::getTablePrefix() . rex::getTempPrefix()) {
// Tabellen die mit rex_tmp_ beginnne, werden nicht exportiert!
$tables[] = $table;
}
}
}
foreach ($tables as $table) {
//---- export metadata
$create = rex_sql::showCreateTable($table);
fwrite($fp, 'DROP TABLE IF EXISTS `' . $table . '`;' . $nl);
fwrite($fp, $create . ';' . $nl);
$fields = $sql->getArray('SHOW FIELDS FROM `' . $table . '`');
foreach ($fields as &$field) {
if (preg_match('#^(bigint|int|smallint|mediumint|tinyint|timestamp)#i', $field['Type'])) {
$field = 'int';
} elseif (preg_match('#^(float|double|decimal)#', $field['Type'])) {
$field = 'double';
} elseif (preg_match('#^(char|varchar|text|longtext|mediumtext|tinytext)#', $field['Type'])) {
$field = 'string';
}
// else ?
}
//---- export tabledata
$start = 0;
$max = $insertSize;
do {
$array = $sql->getArray('SELECT * FROM `' . $table . '` LIMIT ' . $start . ',' . $max, [], PDO::FETCH_NUM);
$count = $sql->getRows();
if ($count > 0 && $start == 0) {
fwrite($fp, $nl . 'LOCK TABLES `' . $table . '` WRITE;');
fwrite($fp, $nl . '/*!40000 ALTER TABLE `' . $table . '` DISABLE KEYS */;');
} elseif ($count == 0) {
break;
}
$start += $max;
$values = [];
foreach ($array as $row) {
$record = [];
foreach ($fields as $idx => $type) {
$column = $row[$idx];
switch ($type) {
case 'int':
$record[] = intval($column);
break;
case 'double':
$record[] = sprintf('%.10F', (double) $column);
break;
case 'string':
default:
$record[] = $sql->escape($column, "'");
break;
}
}
$values[] = $nl . ' (' . implode(',', $record) . ')';
}
if (!empty($values)) {
fwrite($fp, $nl . 'INSERT INTO `' . $table . '` VALUES ' . implode(',', $values) . ';');
unset($values);
}
} while ($count >= $max);
if ($start > 0) {
fwrite($fp, $nl . '/*!40000 ALTER TABLE `' . $table . '` ENABLE KEYS */;');
fwrite($fp, $nl . 'UNLOCK TABLES;' . $nl . $nl);
}
}
fclose($fp);
$hasContent = true;
// Den Dateiinhalt geben wir nur dann weiter, wenn es unbedingt notwendig ist.
if (rex_extension::isRegistered('BACKUP_AFTER_DB_EXPORT')) {
$content = rex_file::get($filename);
$hashBefore = md5($content);
//.........这里部分代码省略.........
示例2: rex_a1_export_db
/**
* Erstellt einen SQL Dump, der die aktuellen Datebankstruktur darstellt.
* Dieser wird in der Datei $filename gespeichert.
*
* @return boolean TRUE wenn ein Dump erstellt wurde, sonst FALSE
*/
function rex_a1_export_db($filename, array $tables = null)
{
global $REX, $I18N;
$fp = @fopen($filename, 'w');
if (!$fp) {
return false;
}
// Im Frontend gibts kein I18N
if (!is_object($I18N)) {
$I18N = rex_create_lang($REX['LANG']);
}
$sql = rex_sql::factory();
$nl = "\n";
$insertSize = 5000;
// ----- EXTENSION POINT
rex_register_extension_point('A1_BEFORE_DB_EXPORT');
// Versionsstempel hinzufügen
fwrite($fp, '## Redaxo Database Dump Version ' . $REX['VERSION'] . $nl);
fwrite($fp, '## Prefix ' . $REX['TABLE_PREFIX'] . $nl);
fwrite($fp, '## charset ' . $I18N->msg('htmlcharset') . $nl . $nl);
// fwrite($fp, '/*!40110 START TRANSACTION; */'.$nl);
if (is_null($tables)) {
$tables = array();
foreach (rex_sql::showTables(1, $REX['TABLE_PREFIX']) as $table) {
if ($table != $REX['TABLE_PREFIX'] . 'user' && substr($table, 0, strlen($REX['TABLE_PREFIX'] . $REX['TEMP_PREFIX'])) != $REX['TABLE_PREFIX'] . $REX['TEMP_PREFIX']) {
// Tabellen die mit rex_tmp_ beginnne, werden nicht exportiert!
$tables[] = $table;
}
}
}
foreach ($tables as $table) {
//---- export metadata
$create = rex_sql::showCreateTable($table);
fwrite($fp, "DROP TABLE IF EXISTS `{$table}`;\n");
fwrite($fp, "{$create};\n");
$fields = $sql->getArray("SHOW FIELDS FROM `{$table}`");
foreach ($fields as $idx => $field) {
if (preg_match('#^(bigint|int|smallint|mediumint|tinyint|timestamp)#i', $field['Type'])) {
$fields[$idx] = 'int';
} elseif (preg_match('#^(float|double|decimal)#', $field['Type'])) {
$fields[$idx] = 'double';
} elseif (preg_match('#^(char|varchar|text|longtext|mediumtext|tinytext)#', $field['Type'])) {
$fields[$idx] = 'string';
}
// else ?
}
//---- export tabledata
$start = 0;
$max = $insertSize;
do {
$sql->freeResult();
$sql->setQuery("SELECT * FROM `{$table}` LIMIT {$start},{$max}");
if ($sql->getRows() > 0 && $start == 0) {
fwrite($fp, "\nLOCK TABLES `{$table}` WRITE;");
fwrite($fp, "\n/*!40000 ALTER TABLE `{$table}` DISABLE KEYS */;");
} elseif ($sql->getRows() == 0) {
break;
}
$start += $max;
$values = array();
while ($sql->hasNext()) {
$record = array();
foreach ($fields as $idx => $type) {
$column = $sql->getValue($idx);
switch ($type) {
case 'int':
$record[] = intval($column);
break;
case 'double':
$record[] = sprintf('%.10F', (double) $column);
break;
case 'string':
default:
$record[] = $sql->escape($column, "'", true);
break;
}
}
$values[] = $nl . ' (' . implode(',', $record) . ')';
$sql->next();
}
if (!empty($values)) {
$values = implode(',', $values);
fwrite($fp, "\nINSERT INTO `{$table}` VALUES {$values};");
unset($values);
}
} while ($sql->getRows() >= $max);
if ($start > 0) {
fwrite($fp, "\n/*!40000 ALTER TABLE `{$table}` ENABLE KEYS */;");
fwrite($fp, "\nUNLOCK TABLES;\n\n");
}
}
fclose($fp);
$hasContent = true;
// Den Dateiinhalt geben wir nur dann weiter, wenn es unbedingt notwendig ist.
//.........这里部分代码省略.........