this is more a question of how do you want to handle the catastrophic failure to connect to your database.
Using die offers the programmer far less sophisticated options, but is quick and easy to write, so might be useful to debug as you develop - you are not likely to leave it like that in your finished product.
In the finished product you may want to variously:
log the error
recover graciously with helpful messages about what the user should do
try a secondary database/table
send an email
… and so on
This is the straight forward way to easily connect your MySQL database with PHP. You can easily use this code in a function and then call that function: