Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Archiwizacja
Forum PHP.pl > Forum > PHP
one_eddie
Czy jest jakis sposob, jakas funkcja pozwalajaca na zrzut struktury oraz danych bazy do zapytan sql?
Levabul
bazê MySql do zapytañ Sql mo¿esz zrzuciæ w PhpMyAdmin
one_eddie
Caly czas pracuje na PHPMA, ale chcialem cos takiego zaimplementowac w swoim skrypcie i nie wiem od czego zaczac.
aleksander
NTF : Algorytmy => php
nocnyMark()
znam dwa:

http://sourceforge.net/projects/phpmybackup/

i

skrypt szewo
prostrzy w funkcja i w uzyciu - sama esencja
nie moge aktualnie dostac sie do niego na strone,
wiec wklejam go ponizej

  1. <? 
  2. // MySQL hostname
  3. $host =  ;
  4.  
  5. //MySQL basename
  6. $dbname =  ;
  7. // MySQL user
  8. $uname =  ;
  9. // MySQL password
  10. $upass =  ;
  11. // set FALSE to get table content
  12. $structure_only = false;
  13. //set TRUE to to get file with dump
  14. $output = true;
  15.  
  16.  
  17. //////////////////////////////////////////////////
  18. //
  19. // phpMyDump v 1.0
  20. //
  21. // check for new version
  22. // http://szewo.com/php/mydump/eng
  23. //
  24. // some functions are adapted from the phpMyAdmin 
  25. //
  26. // do not change anything below this line
  27. //////////////////////////////////////////////////
  28. function mysqlbackup($host,$dbname, $uid, $pwd, $structure_only, $crlf) {
  29.  
  30.  $con=@mysql_connect(&#092;"localhost\",$uid, $pwd) or die(\"Could not connect\");
  31.  $db=@mysql_select_db($dbname,$con) or die(&#092;"Could not select db\");
  32.  
  33.  // here we check MySQL Version
  34.  $result=@mysql_query(&#092;"SELECT VERSION() AS version\"); 
  35.  if ($result != FALSE && @mysql_num_rows($result) > 0) {
  36. $row  = @mysql_fetch_array($result);
  37. $match = explode('.', $row['version']);
  38.  } else {
  39. $result=@mysql_query(&#092;"SHOW VARIABLES LIKE 'version'\"); 
  40. if ($result != FALSE && @mysql_num_rows($result) > 0){
  41.  $row  = @mysql_fetch_row($result);
  42.  $match = explode('.', $row[1]);
  43. }
  44.  }
  45.  
  46.  if (!isset($match) || !isset($match[0])) {
  47. $match[0] = 3;
  48.  }
  49.  if (!isset($match[1])) {
  50. $match[1] = 21;
  51.  }
  52.  if (!isset($match[2])) {
  53. $match[2] = 0;
  54.  }
  55.  if(!isset($row)) {
  56. $row = '3.21.0';
  57.  }
  58.  
  59.  define('MYSQL_INT_VERSION', (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2])));
  60.  define('MYSQL_STR_VERSION', $row['version']);
  61.  unset($match);
  62.  
  63.  $sql = &#092;"# MySQL dump by phpMyDump\".$crlf;
  64.  $sql.= &#092;"# Host: $host Database: $dbname\".$crlf;
  65.  $sql.= &#092;"----------------------------\".$crlf;
  66.  $sql.= &#092;"# Server version: \".MYSQL_STR_VERSION.$crlf;
  67.  
  68.  $sql.= $crlf.$crlf.$crlf;  
  69.  out(1,$sql);
  70.  $res=@mysql_list_tables($dbname);
  71.  $nt=@mysql_num_rows($res);
  72.  
  73.  for ($a=0;$a<$nt;$a++) {
  74. $row=mysql_fetch_row($res);
  75. $tablename=$row[0];
  76.  
  77. $sql=$crlf.&#092;"# ----------------------------------------\".$crlf.\"# table structure for table '$tablename' \".$crlf;
  78. // For MySQL < 3.23.20
  79. if (MYSQL_INT_VERSION >= 32321) {
  80.  $result=mysql_query(&#092;"SHOW CREATE TABLE $tablename\");
  81.  if ($result != FALSE && mysql_num_rows($result) > 0) {
  82. $tmpres = mysql_fetch_array($result);
  83. $pos  = strpos($tmpres[1], ' (');
  84. $tmpres[1]  = substr($tmpres[1], 0, 13)
  85.  . $tmpres[0]
  86.  . substr($tmpres[1], $pos);
  87.  
  88. $sql .= $tmpres[1].&#092;";\".$crlf.$crlf;
  89.  }
  90.  mysql_free_result($result);
  91. } else { 
  92.  $sql.=&#092;"CREATE TABLE $tablename(\".$crlf;
  93.  $result=mysql_query(&#092;"show fields from $tablename\",$con);
  94.  
  95.  while ($row = mysql_fetch_array($result)) {
  96. $sql .= &#092;" \".$row['Field'];
  97. $sql .= ' ' . $row['Type'];
  98. if (isset($row['Default']) && $row['Default'] != '') {
  99.  $sql .= ' DEFAULT '' . $row['Default'] . ''';
  100. }
  101. if ($row['Null'] != 'YES') {
  102.  $sql .= ' NOT NULL';
  103. }
  104. if ($row['Extra'] != '') {
  105.  $sql .= ' ' . $row['Extra'];
  106. }
  107. $sql .= &#092;",\".$crlf;
  108.  }
  109.  
  110.  mysql_free_result($result);
  111.  $sql = ereg_replace(',' . $crlf . '$', '', $sql);
  112.  
  113.  $result = mysql_query(&#092;"SHOW KEYS FROM $tablename\");
  114. while ($row = mysql_fetch_array($result)) {
  115.  $ISkeyname = $row['Key_name'];
  116.  $IScomment = (isset($row['Comment'])) ? $row['Comment'] : '';
  117.  $ISsub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : '';
  118.  if ($ISkeyname != 'PRIMARY' && $row['Non_unique'] == 0) {
  119. $ISkeyname = &#092;"UNIQUE|$kname\";
  120.  }
  121.  if ($IScomment == 'FULLTEXT') {
  122. $ISkeyname = 'FULLTEXT|$kname';
  123.  }
  124.  if (!isset($index[$ISkeyname])) {
  125. $index[$ISkeyname] = array();
  126.  }
  127.  if ($ISsub_part > 1) {
  128. $index[$ISkeyname][] = $row['Column_name'] . '(' . $ISsub_part . ')';
  129.  } else {
  130. $index[$ISkeyname][] = $row['Column_name'];
  131.  }
  132. } 
  133.  
  134. while (list($x, $columns) = @each($index)) {
  135.  $sql  .= &#092;",\".$crlf;
  136.  if ($x == 'PRIMARY') {
  137. $sql .= ' PRIMARY KEY (';
  138. } else if (substr($x, 0, 6) == 'UNIQUE') {
  139. $sql .= ' UNIQUE ' . substr($x, 7) . ' (';
  140.  } else if (substr($x, 0, 8) == 'FULLTEXT') {
  141. $sql .= ' FULLTEXT ' . substr($x, 9) . ' (';
  142.  } else {
  143. $sql .= ' KEY ' . $x . ' (';
  144.  }
  145.  $sql  .= implode($columns, ', ') . ')';
  146. } 
  147. $sql .= $crlf.&#092;");\".$crlf.$crlf;
  148.  
  149. } 
  150. out(1,$sql);
  151.  if ($structure_only == FALSE) {
  152. // here we get table content
  153. $result = mysql_query(&#092;"SELECT * FROM $tablename\");
  154. $fields_cnt  = mysql_num_fields($result);
  155. while ($row = mysql_fetch_row($result)) {
  156.  $table_list  = '(';
  157.  for ($j = 0; $j < $fields_cnt; $j++) {
  158. $table_list .= mysql_field_name($result, $j) . ', ';
  159.  }
  160.  $table_list = substr($table_list, 0, -2);
  161.  $table_list  .= ')';
  162.  
  163.  $sql = 'INSERT INTO ' . $tablename 
  164.  . ' VALUES (';
  165.  for ($j = 0; $j < $fields_cnt; $j++) {
  166. if (!isset($row[$j])) {
  167.  $sql .= ' NULL, ';
  168. } else if ($row[$j] == '0' || $row[$j] != '') {
  169.  $type = mysql_field_type($result, $j);
  170.  // a number
  171.  if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
  172. $type == 'bigint' ||$type == 'timestamp') {
  173. $sql .= $row[$j] . ', ';
  174.  }
  175.  // a string
  176.  else {
  177. $dummy = '';
  178. $srcstr = $row[$j];
  179. for ($xx = 0; $xx < strlen($srcstr); $xx++) {
  180.  $yy = strlen($dummy);
  181.  if ($srcstr[$xx] == '')  $dummy .= '';
  182.  if ($srcstr[$xx] == ''')  $dummy .= ''';
  183.  if ($srcstr[$xx] == \"x00\") $dummy .= '0';
  184.  if ($srcstr[$xx] == \"x0a\") $dummy .= 'n';
  185.  if ($srcstr[$xx] == \"x0d\") $dummy .= 'r';
  186.  if ($srcstr[$xx] == \"x1a\") $dummy .= 'Z';
  187.  if (strlen($dummy) == $yy) $dummy .= $srcstr[$xx];
  188. }
  189. $sql .= \"'&#092;" . $dummy . \"', \";
  190.  }
  191. } else {
  192.  $sql .= &#092;"'', \";
  193. } // end if
  194.  } // end for
  195.  $sql = ereg_replace(', $', '', $sql);
  196.  $sql .= &#092;");\".$crlf;
  197.  out(1,$sql);  
  198.  
  199. } 
  200. } 
  201.  }
  202.  return;
  203. }
  204.  
  205. function define_crlf() {
  206.  global $HTTP_USER_AGENT;
  207.  $ucrlf = &#092;"n\";
  208.  if (strstr($HTTP_USER_AGENT, 'Win')) {
  209. $ucrlf = &#092;"rn\";
  210.  }
  211.  else if (strstr($HTTP_USER_AGENT, 'Mac')) {
  212. $ucrlf = &#092;"r\";
  213.  }
  214.  else {
  215. $ucrlf = &#092;"n\";
  216.  }
  217.  return $ucrlf;
  218. } 
  219.  
  220. //print the result
  221. function out($fptr,$s)  { 
  222.  echo $s; 
  223. } 
  224.  
  225. if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  226.  define('USER_BROWSER_AGENT', 'OPERA');
  227. } else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  228.  define('USER_BROWSER_AGENT', 'IE');
  229. } else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  230.  define('USER_BROWSER_AGENT', 'OMNIWEB');
  231. } else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  232.  define('USER_BROWSER_AGENT', 'MOZILLA');
  233. } else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) {
  234.  define('USER_BROWSER_AGENT', 'KONQUEROR');
  235. } else {
  236.  define('USER_BROWSER_AGENT', 'OTHER');
  237. }
  238.  
  239. $mime_type = (USER_BROWSER_AGENT == 'IE' || USER_BROWSER_AGENT == 'OPERA')
  240.  ? 'application/octetstream'
  241.  : 'application/octet-stream';
  242.  
  243.  
  244. $now = gmdate('D, d M Y H:i:s') . ' GMT';
  245. $filename = $dbname;
  246. $ext = &#092;"sql\";
  247. $crlf = define_crlf();
  248. // Send headers
  249. if ($output == true) {
  250.  header('Content-Type: ' . $mime_type);
  251.  header('Expires: ' . $now);
  252.  // lem9 & loic1: IE need specific headers
  253.  if (USER_BROWSER_AGENT == 'IE') {
  254. header('Content-Disposition: inline; filename=\"' . $filename . '.' . $ext . '\"');
  255. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  256. header('Pragma: public');
  257.  } else {
  258. header('Content-Disposition: attachment; filename=\"' . $filename . '.' . $ext . '\"');
  259. header('Pragma: no-cache');
  260.  
  261.  }
  262.  mysqlbackup($host,$dbname,$uname,$upass,$structure_only,$crlf);
  263. } 
  264.  else {
  265.  echo &#092;"<html><body><pre>\";
  266.  echo htmlspecialchars(mysqlbackup($host,$dbname,$uname,$upass,$structure_only,$crlf));
  267.  echo &#092;"</PRE></BODY></HTML>\";
  268. }
  269. ?>
NuLL
http://www.ozerov.de/bigdump.php
one_eddie
Dzieki skrypcik szewo bardzo pomogl.
Znalazlem jeszcze zrodla programu mysqldump wiec sprawa jest juz zalatwiona.
Dzieki.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.