Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Zapis struktury mysql przez php
Johnas
post
Post #1





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


Witam, próbuje zrobić zapis struktury bazy danych mysql, ale mam problem... mianowicie nie mogę foreachować "SHOW Tables"... wie ktoś może co jest nie tak w tym kodzie ?

  1. foreach ($tables as $table) {
  2. echo $table["Table_in_4um"];
  3. echo "CREATE TABLE IF NOT EXISTS `$table`";
  4. $structure = $engine->mysql->query("DESCRIBE ".$table);
  5. print_r($structure);
  6. echo "<br><br>";
  7. }


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Johnas
post
Post #2





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


Tak ma być... Chodzi o to że dałem Table zamiast Tables

  1. foreach ($tables as $table) {
  2. $table = $table["Tables_in_".$config->DBname];
  3. $primery = "";
  4. $structures = $engine->mysql->query("DESCRIBE ".$table);
  5.  
  6. $table = str_replace($engine->prefix, "", $table);
  7. $mysql .= '$adds['.$c.']["mysql"] = "CREATE TABLE IF NOT EXISTS `".$engine->prefix."'.$table.'` ( '.PHP_EOL;
  8. foreach ($structures as $structure) {
  9. $mysql .= "`".$structure["Field"]."` ".$structure["Type"]." ";
  10. if ($structure["Null"] == "NO")
  11. $mysql .= "NOT NULL";
  12. else
  13. $mysql .= "NULL";
  14. if (strlen($structure["Extra"]) > 0)
  15. $mysql .= " ".$structure["Extra"].",".PHP_EOL;
  16. else
  17. $mysql .= ",".PHP_EOL;
  18. if ($structure["Key"] == "PRI")
  19. $primery = 'PRIMARY KEY (`'.$structure["Field"].'`)';
  20. }
  21. $mysql .= $primery.PHP_EOL;
  22. $mysql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\";".PHP_EOL;
  23.  
  24. $mysql .= '$adds['.$c.']["name"] = "'.$table.'";'.PHP_EOL;
  25. $c++;
  26. }


Jedna literówka zaburza działanie programu
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 20:13