0

My 1st function:

function db_connect_error_mail ($txt) {
mail(admin_email,mail_subject01,$txt);} //1st three variables come from constants at config.php

and 2nd function:

function connectdb() {
  $dbc = mysqli_connect (db_host, db_user, db_password, db_name); //variables come from constants at config.php
  if (!$dbc) 
{
$txt = mysqli_connect_errno().mysqli_connect_error();
db_connect_error_mail($txt);
unset ($txt);
die('custom error message to inform viewer');
} else 
    {
        return $dbc;
    }
}

My question:

Is it okey in index.php just to call connectdb()? If db connection couldn't be set, will I get an email also? (assume that server's mail function works all time)

j0k
  • 22,600
  • 28
  • 79
  • 90
Andre Chenier
  • 1,166
  • 2
  • 18
  • 37

1 Answers1

0

If you will call die before db_connect_error_mail() then no, you won't receive your e-mail as die() function stops execution of any further code.

You might however call your die function after sending the error e-mail. this way you will get both: notification mail and an error message.

MarcinWolny
  • 1,600
  • 2
  • 27
  • 40