2013-02-01 45 views
0

我的第一个功能:在另一个自定义功能的自定义函数的声明

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

和第2个功能:

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; 
    } 
} 

我的问题:

是否好于index.php文件只需调用connectdb()?如果db连接不能设置,我会收到一封电子邮件吗? (假设服务器的邮件功能工作的所有时间)

+0

猜,是的,只要你在'index.php'中包含'config.php'。 :) –

+0

@Praveen库马尔:是的,我包括config.php。 –

+0

Andre什么... ??? –

回答

0

如果你要给db_connect_error_mail死()则没有,你会不会为die()功能停止任何进一步的代码执行接收电子邮件。

然而,您可能会在发送错误电子邮件后致电您的模具功能。这样你会得到两个:通知邮件和错误消息。