MySqlBuilder.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Illuminate\Database\Schema;
  3. class MySqlBuilder extends Builder
  4. {
  5. /**
  6. * Determine if the given table exists.
  7. *
  8. * @param string $table
  9. * @return bool
  10. */
  11. public function hasTable($table)
  12. {
  13. $table = $this->connection->getTablePrefix().$table;
  14. return count($this->connection->select(
  15. $this->grammar->compileTableExists(), [$this->connection->getDatabaseName(), $table]
  16. )) > 0;
  17. }
  18. /**
  19. * Get the column listing for a given table.
  20. *
  21. * @param string $table
  22. * @return array
  23. */
  24. public function getColumnListing($table)
  25. {
  26. $table = $this->connection->getTablePrefix().$table;
  27. $results = $this->connection->select(
  28. $this->grammar->compileColumnListing(), [$this->connection->getDatabaseName(), $table]
  29. );
  30. return $this->connection->getPostProcessor()->processColumnListing($results);
  31. }
  32. /**
  33. * Drop all tables from the database.
  34. *
  35. * @return void
  36. */
  37. public function dropAllTables()
  38. {
  39. $tables = [];
  40. foreach ($this->getAllTables() as $row) {
  41. $row = (array) $row;
  42. $tables[] = reset($row);
  43. }
  44. if (empty($tables)) {
  45. return;
  46. }
  47. $this->disableForeignKeyConstraints();
  48. $this->connection->statement(
  49. $this->grammar->compileDropAllTables($tables)
  50. );
  51. $this->enableForeignKeyConstraints();
  52. }
  53. /**
  54. * Get all of the table names for the database.
  55. *
  56. * @return array
  57. */
  58. protected function getAllTables()
  59. {
  60. return $this->connection->select(
  61. $this->grammar->compileGetAllTables()
  62. );
  63. }
  64. }