Laravel | MySQL Database Connection (original) (raw)

Last Updated : 30 Dec, 2019

The database is an important element in any application. Laravel by default provides the support of MySQL. MySQL is a well known, open-source RDBMS (Relational Database Management System).Process for Connecting to the Database:

Custom Error Message: If you don’t want Laravel to handle it and give a predefined message then you can use try . . . catch block as shown below or can directlyreplace the step 6 codes with this lines of code:

html `

GeeksforGeeks
getPdo()) { echo "Successfully connected to the database => " .DB::connection()->getDatabaseName(); } } catch (Exception $e) { echo "Unable to connect"; } ?>

`

Here, if unsuccessful then will print the message written in the catch block: Reference: https://laravel.com/docs/6.x/database