Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Kodowanie znaków prze exportcie bazy MySQL do pliku
krzesik
post
Post #1





Grupa: Zarejestrowani
Postów: 516
Pomógł: 1
Dołączył: 25.08.2012

Ostrzeżenie: (0%)
-----


Witam,
mam poniższą klasę do zrzutu bazy MySQL do pliku, wszystko ładnie działa, ale mam problem z polskimi ogonkami "ą", "ź", "ś" - wpisuje mi krzaki, proszę o podpowiedź

  1. .....
  2. function createDump() {
  3. // Set line feed
  4. $lf = "\n";
  5.  
  6. $resource = mysql_connect($this->getHost(), $this->getDBuser(), $this->getDBpassword());
  7. mysql_select_db($this->getDbname(), $resource);
  8. $result = mysql_query("SHOW TABLES");
  9. $tables = $this->result2Array(0, $result);
  10. foreach ($tables as $tblval) {
  11. $result = mysql_query("SHOW CREATE TABLE `$tblval`");
  12. $createtable[$tblval] = $this->result2Array(1, $result);
  13. }
  14. // Set header
  15. $output = "#". $lf;
  16. $output .= "# DUmp" . $lf;
  17. $output .= "# Version 2.6" . $lf;
  18. $output .= "# ". $lf;
  19. $output .= "# Host: " . $this->getHost() . $lf;
  20. $output .= "# Czas wygenerowania: " . date("M j, Y at H:i") . $lf;
  21. $output .= "# Wersja serwera: ". mysql_get_server_info() . $lf;
  22. $output .= "# Wersja php: " . phpversion() . $lf;
  23. $output .= "# Baza danych : `" . $this->getDBname() . "`" . $lf;
  24. $output .= "#";
  25.  
  26. // Generate dumptext for the tables.
  27. foreach ($tables as $tblval)
  28. {
  29. If (($tblval!="bip_logowanie") and ($tblval!="bip_users"))
  30. {
  31. $output .= $lf . $lf . "# --$tabela------------------------------------------------------" . $lf . $lf;
  32. $output .= "#". $lf . "# Struktura tabeli dla `$tblval`" . $lf;
  33. $output .= "#" . $lf . $lf;
  34. // Generate DROP TABLE statement when client wants it to.
  35. if($this->isDroptables())
  36. {
  37. $output .= "DROP TABLE IF EXISTS `$tblval`;" . $lf;
  38. }
  39. $output .= $createtable[$tblval][0].";" . $lf;
  40. $output .= $lf;
  41. $output .= "#". $lf . "# Zrzut danych tabeli `$tblval`". $lf . "#" . $lf;
  42. $result = mysql_query("SELECT * FROM `$tblval`");
  43. $rows = $this->loadObjectList("", $result);
  44. foreach($rows as $row)
  45. {
  46.  
  47. $insertdump = $lf;
  48. $insertdump .= "INSERT INTO `$tblval` VALUES (";
  49. $arr = $this->object2Array($row);
  50. foreach($arr as $key => $value)
  51. {
  52. $value = addslashes($value);
  53. //$value = str_replace("n", 'rn', $value);
  54. //$value = str_replace("r", '', $value);
  55.  
  56. $insertdump .= "'$value',";
  57. }
  58. $output .= rtrim($insertdump,',') . ");";
  59. }
  60. }
  61. }
  62. mysql_close($resource);
  63. return $output;
  64. }
  65.  
  66. // Private function object2Array.
  67. function object2Array($obj) {
  68. $array = null;
  69. if(is_object($obj)) {
  70. $array = array();
  71. foreach (get_object_vars($obj) as $key => $value) {
  72. if(is_object($value))
  73. $array[$key] = $this->object2Array($value);
  74. else
  75. $array[$key] = $value;
  76. }
  77. }
  78. return $array;
  79. }
  80.  
  81. // Private function loadObjectList.
  82. function loadObjectList($key='', $resource) {
  83. $array = array();
  84. while ($row = mysql_fetch_object($resource)) {
  85. if ($key)
  86. $array[$row->$key] = $row;
  87. else
  88. $array[] = $row;
  89. }
  90. mysql_free_result($resource);
  91. return $array;
  92. }
  93.  
  94. // Private function result2Array.
  95. function result2Array($numinarray = 0, $resource) {
  96. $array = array();
  97. while ($row = mysql_fetch_row($resource)) {
  98. $array[] = $row[$numinarray];
  99. }
  100. mysql_free_result($resource);
  101. return $array;
  102. }
  103. }
  104. .....
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 13:34