$database = new PDO('mysql:host=localhost; dbname=company', 'username', 'password'); if ($database->hasTable('employees')) { echo 'Employees table exists!'; } else { echo 'Employees table does not exist!'; }
use Illuminate\Support\Facades\Schema; if (Schema::hasTable('orders')) { echo 'Orders table exists!'; } else { echo 'Orders table does not exist!'; }In the second example, we are using the Laravel package library which contains the `Schema` facade to interact with the database. Overall, the `hasTable` method in PHP is a useful function for developers to check if a table exists in a particular database. It can be used with various package libraries and frameworks such as Laravel, which makes the database interaction effortless.