28 lines
827 B
PHP
Executable File
28 lines
827 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Database\QueryException;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class TestDBController extends BaseApiController
|
|
{
|
|
public function index()
|
|
{
|
|
try {
|
|
$result = DB::select('SELECT 1 AS ok');
|
|
if (!empty($result)) {
|
|
return $this->success(['message' => 'Database connection is successful.'], 'Database check completed');
|
|
}
|
|
|
|
return $this->respondError('Database connection failed', Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
} catch (QueryException $e) {
|
|
return $this->respondError(
|
|
'Database connection failed: ' . $e->getMessage(),
|
|
Response::HTTP_INTERNAL_SERVER_ERROR
|
|
);
|
|
}
|
|
}
|
|
}
|