📄 acp_database.php
字号:
else if (preg_match('#date|timestamp#i', $ary_type[$i])) { if (empty($str_val)) { $str_quote = ''; } else { $str_quote = "'"; } } else { $str_quote = ''; $str_empty = 'NULL'; } if (empty($str_val) && $str_val !== '0') { $str_val = $str_empty; } $schema_vals[$i] = $str_quote . $str_val . $str_quote; $schema_fields[$i] = $ary_name[$i]; } // Take the ordered fields and their associated data and build it // into a valid sql statement to recreate that field in the data. $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n"; if ($store == true) { $write($fp, $sql_data); } if ($download == true) { fwrite($fh, $sql_data); } $sql_data = ''; } $db->sql_freeresult($result); // Write out the sequence statements if ($store == true) { $write($fp, $seq); } if ($download == true) { if (!empty($oper)) { echo $oper($seq); } else { echo $seq; } } $seq = ''; break; case 'mssql_odbc': $ary_type = $ary_name = array(); $ident_set = false; // Grab all of the data from current table. $sql = "SELECT * FROM $table_name"; $result = $db->sql_query($sql); $retrieved_data = odbc_num_rows($result); if ($retrieved_data) { $sql = "SELECT 1 as has_identity FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1"; $result2 = $db->sql_query($sql); $row2 = $db->sql_fetchrow($result2); if (!empty($row2['has_identity'])) { $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n"; $ident_set = true; } $db->sql_freeresult($result2); } $i_num_fields = odbc_num_fields($result); for ($i = 0; $i < $i_num_fields; $i++) { $ary_type[$i] = odbc_field_type($result, $i + 1); $ary_name[$i] = odbc_field_name($result, $i + 1); } while ($row = $db->sql_fetchrow($result)) { $schema_vals = $schema_fields = array(); // Build the SQL statement to recreate the data. for ($i = 0; $i < $i_num_fields; $i++) { $str_val = $row[$ary_name[$i]]; if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i])) { $str_quote = "'"; $str_empty = ''; $str_val = addslashes($str_val); } else if (preg_match('#date|timestamp#i', $ary_type[$i])) { if (empty($str_val)) { $str_quote = ''; } else { $str_quote = "'"; } } else { $str_quote = ''; $str_empty = 'NULL'; } if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) { $str_val = $str_empty; } $schema_vals[$i] = $str_quote . $str_val . $str_quote; $schema_fields[$i] = $ary_name[$i]; } // Take the ordered fields and their associated data and build it // into a valid sql statement to recreate that field in the data. $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n"; if ($store == true) { $write($fp, $sql_data); } if ($download == true) { fwrite($fh, $sql_data); } $sql_data = ''; } $db->sql_freeresult($result); if ($retrieved_data) { $sql_data = "\nGO\n"; if ($ident_set) { $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n"; } } break; case 'mssql': $ary_type = $ary_name = array(); $ident_set = false; // Grab all of the data from current table. $sql = "SELECT * FROM $table_name"; $result = $db->sql_query($sql); $retrieved_data = mssql_num_rows($result); $i_num_fields = mssql_num_fields($result); for ($i = 0; $i < $i_num_fields; $i++) { $ary_type[$i] = mssql_field_type($result, $i); $ary_name[$i] = mssql_field_name($result, $i); } if ($retrieved_data) { $sql = "SELECT 1 as has_identity FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMNPROPERTY(object_id('$table_name'), COLUMN_NAME, 'IsIdentity') = 1"; $result2 = $db->sql_query($sql); $row2 = $db->sql_fetchrow($result2); if (!empty($row2['has_identity'])) { $sql_data .= "\nSET IDENTITY_INSERT $table_name ON\nGO\n"; $ident_set = true; } $db->sql_freeresult($result2); } while ($row = $db->sql_fetchrow($result)) { $schema_vals = $schema_fields = array(); // Build the SQL statement to recreate the data. for ($i = 0; $i < $i_num_fields; $i++) { $str_val = $row[$ary_name[$i]]; if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i])) { $str_quote = "'"; $str_empty = ''; $str_val = addslashes($str_val); } else if (preg_match('#date|timestamp#i', $ary_type[$i])) { if (empty($str_val)) { $str_quote = ''; } else { $str_quote = "'"; } } else { $str_quote = ''; $str_empty = 'NULL'; } if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) { $str_val = $str_empty; } $schema_vals[$i] = $str_quote . $str_val . $str_quote; $schema_fields[$i] = $ary_name[$i]; } // Take the ordered fields and their associated data and build it // into a valid sql statement to recreate that field in the data. $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n"; if ($store == true) { $write($fp, $sql_data); } if ($download == true) { fwrite($fh, $sql_data); } $sql_data = ''; } $db->sql_freeresult($result); if ($retrieved_data) { $sql_data = "\nGO\n"; if ($ident_set) { $sql_data .= "\nSET IDENTITY_INSERT $table_name OFF\nGO\n"; } } break; case 'firebird': $ary_type = $ary_name = array(); // Grab all of the data from current table. $sql = "SELECT * FROM $table_name"; $result = $db->sql_query($sql); $i_num_fields = ibase_num_fields($result); for ($i = 0; $i < $i_num_fields; $i++) { $info = ibase_field_info($result, $i); $ary_type[$i] = $info['type']; $ary_name[$i] = $info['name']; } while ($row = $db->sql_fetchrow($result)) { $schema_vals = $schema_fields = array(); // Build the SQL statement to recreate the data. for ($i = 0; $i < $i_num_fields; $i++) { $str_val = $row[strtolower($ary_name[$i])]; if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i])) { $str_quote = "'"; $str_empty = ''; $str_val = addslashes($str_val); } else if (preg_match('#date|timestamp#i', $ary_type[$i])) { if (empty($str_val)) { $str_quote = ''; } else { $str_quote = "'"; } } else { $str_quote = ''; $str_empty = 'NULL'; } if (empty($str_val) && $str_val !== '0') { $str_val = $str_empty; } $schema_vals[$i] = $str_quote . $str_val . $str_quote; $schema_fields[$i] = "'" . $ary_name[$i] . "'"; } // Take the ordered fields and their associated data and build it // into a valid sql statement to recreate that field in the data. $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n"; if ($store == true) { $write($fp, $sql_data); } if ($download == true) { fwrite($fh, $sql_data); } $sql_data = ''; } $db->sql_freeresult($result); break; case 'oracle': $ary_type = $ary_name = array(); // Grab all of the data from current table. $sql = "SELECT * FROM $table_name"; $result = $db->sql_query($sql); $i_num_fields = ocinumcols($result); for ($i = 0; $i < $i_num_fields; $i++) { $ary_type[$i] = ocicolumntype($result, $i + 1); $ary_name[$i] = ocicolumnname($result, $i + 1); } while ($row = $db->sql_fetchrow($result)) { $schema_vals = $schema_fields = array(); // Build the SQL statement to recreate the data. for ($i = 0; $i < $i_num_fields; $i++) { $str_val = $row[$ary_name[$i]]; if (preg_match('#char|text|bool|raw#i', $ary_type[$i])) { $str_quote = "'"; $str_empty = ''; $str_val = addslashes($str_val); } else if (preg_match('#date|timestamp#i', $ary_type[$i])) { if (empty($str_val)) { $str_quote = ''; } else { $str_quote = "'"; } } else { $str_quote = ''; $str_empty = 'NULL'; } if (empty($str_val) && $str_val !== '0') { $str_val = $str_empty; } $schema_vals[$i] = $str_quote . $str_val . $str_quote; $schema_fields[$i] = '"' . $ary_name[$i] . "'"; } // Take the ordered fields and their associated data and build it // into a valid sql statement to recreate that field in the data. $sql_data .= "INSERT INTO $table_name (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\n"; if ($store == true) { $write($fp, $sql_data); } if ($download == true) { fwrite($fh, $sql_data); } $sql_data = ''; } $db->sql_freeresult($result); break; } } } switch ($db->sql_layer) { case 'sqlite': case 'postgres': $sql_data .= "COMMIT;"; break; case 'mssql': case 'mssql_odbc': $sql_data .= "COMMIT\nGO"; break; } if ($store == true) { $write($fp, $sql_data); $close($fp); } if ($download == true) { fwrite($fh, $sql_data); fclose($fh); exit; } unset($sql_data); add_log('admin', 'LOG_DB_BACKUP'); trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action)); break; default: $tables = array(); switch ($db->sql_layer) { case 'sqlite': $sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (strlen($table_prefix) == 0 || strpos($row['name'], $table_prefix) === 0) { $tables[] = $row['name']; } } $db->sql_freeresult($result); break; case 'mysqli': case 'mysql4': case 'mysql': $sql = "SHOW TABLES LIKE '{$table_prefix}%'"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $tables[] = current($row); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -