Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php][mysql] jak sprawdzić czy tabela istnieje ?
Taifun
post
Post #1





Grupa: Zarejestrowani
Postów: 222
Pomógł: 2
Dołączył: 10.07.2007

Ostrzeżenie: (10%)
X----


Jak sprawdzić czy tabela istnieje w danej bazie mysql?
Go to the top of the page
+Quote Post
kossa
post
Post #2





Grupa: Zarejestrowani
Postów: 1 165
Pomógł: 9
Dołączył: 9.04.2002
Skąd: Toruń

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


możesz np. tak

  1. <?php
  2. function table_exists($table)
  3. {
  4. $un = "";
  5. $pass = "";
  6. $db = "";
  7. $host = "localhost";
  8. $sql = mysql_connect($host, $un, $pass) or die(mysql_error());
  9. mysql_select_db($db, $sql) or die(mysql_error());
  10. $result = mysql_list_tables($db) or die(mysql_error());
  11. while ($row = mysql_fetch_row($result)) {
  12. if($row[0]==$table)
  13. {
  14. return true;
  15. }
  16. else 
  17. {
  18. return false;
  19. }
  20.  
  21. }
  22. }
  23. ?>


poza tym jest google i tam mysql + table + exist da Tobie odpowiedź

Łukasz

Ten post edytował kossa 14.08.2007, 10:29:37
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 19.12.2025 - 13:28