Securely connecting to my DB Hello all I have a short question. Is this a good and secure way to connect to my DB ?
session_start();

$servername = &quot;localhost&quot;;
$un = &quot;username&quot;;
$password = &quot;password&quot;;
$dbname = &quot;project&quot;;

$timezone = date_default_timezone_set(&quot;America/New_York&quot;);

// Create connection
$con = mysqli_connect($servername, $un, $password, $dbname);

if($con == true) {
}

// Check connection
if ($con-&gt;connect_error) {
    die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
}
I agree with Anonymous that there isn't much to review here.
I would like to point out a few general things.
The db connection credentials are the type of thing that I'd put in a config.php file and include it where necessary.
$timezone is probably going to be useless in the longterm.  date_default_timezone_set() returns a boolean value to inform you of whether or not you have supplied a valid timezone.  Basically, once this tested once, there is no need to check the return value ever again (until it is changed, of course).
$dbCredentials = [
    &quot;localhost&quot;, //server name
    &quot;username&quot;,
    &quot;password&quot;,
    database&quot;database&quot;
];

date_default_timezone_set(&quot;America/New_York&quot;);

Then just include the file and connect by unpacking the indexed array of credentials like this:
$con = new mysqli(...$dbCredentials);

Notice this is object-oriented syntax.  You should not be mixing styles.
When you are in a development environment (not a production environment), you may return raw error messages. In production, you must never provide raw error messages to users.
When checking for a failed connection, a falsey check (no function call) will be sufficient.  It is vital that you spell your connection variable correctly.
if (!$con) {
    die(&quot;Connection failed: &quot; . $con-&gt;connect_error);
}

That said, an overarching refinement is to perform error handling elsewhere. See YourCommonSense's advice on error reporting.
session_start(); is usually something that you would put at the top of an include that is run before anything else.