Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Determine table existence
  2. SELECT * FROM table WHERE FALSE;
  3.        
  4. SELECT * FROM table WHERE 0;
  5.        
  6. SELECT * FROM table WHERE column = false;
  7.        
  8. if there's table `table`
  9.     return 0 rows (minimal database overhead) and valid resource
  10. else
  11.     return false
  12.        
  13. SELECT count(*)
  14. FROM information_schema.tables
  15. WHERE table_schema = <schema-or-db-name>
  16. AND table_name = <table-or-view-name>
  17.        
  18. $sql="SELECT * FROM $table";
  19. $result=mysql_query($sql);
  20. if (!$result)
  21. {
  22. // table does not exist
  23. }
  24.        
  25. $sql="SELECT * FROM $table where user_id = 1";