Laravel 5.1 - Checking a Database Connection

前端 未结 6 1524
粉色の甜心
粉色の甜心 2020-12-13 02:10

I am trying to check if a database is connected in Laravel.

I\'ve looked around the documentation and can\'t find anything. The closest thing I\'ve found is this, bu

6条回答
  •  不思量自难忘°
    2020-12-13 02:22

    Try just getting the underlying PDO instance. If that fails, then Laravel was unable to connect to the database!

    // Test database connection
    try {
        DB::connection()->getPdo();
    } catch (\Exception $e) {
        die("Could not connect to the database.  Please check your configuration. error:" . $e );
    }
    

提交回复
热议问题