Check for database connection, otherwise display message

后端 未结 3 1248
暖寄归人
暖寄归人 2021-02-05 09:33

I would like to check if the website can connect to mySQL. If not, I would like to display an error saying that the user should try to access the page again in a few minutes...<

3条回答
  •  臣服心动
    2021-02-05 10:03

    very basic:

    
    

    result:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) in /home/user/public_html/zdel1.php on line 6 try again in some minutes, please

    as per Wrikken's recommendation below, check out a complete error handler for more complex, efficient and elegant solutions: http://www.php.net/manual/en/function.set-error-handler.php

提交回复
热议问题