Welcome Guest, Not a member yet? Register   Sign In
How can I have a warning of a Database connection error emailed to me?
#1

[eluser]Banana Man[/eluser]
If for example the server is working fine, but the connection to the database has failed for whatever reason, how would you recommend going about emailing details of the error ?

Thanks in advance
#2

[eluser]TheFuzzy0ne[/eluser]
You'll probably need to override the database() method in the Loader class, and tell it to load your own version of DB.php.

EDIT: Wow, I can't believe Banana Man would actually ask me for help. I'm honoured! Tongue
#3

[eluser]Banana Man[/eluser]
Thanks v much chief for your response, i'll look into that, although i read from the user guide that database is one of the libraries you cannot extend ?
#4

[eluser]Banana Man[/eluser]
i'm gonna go have myself a banana and think about it, thanks again
:cheese:
#5

[eluser]TheFuzzy0ne[/eluser]
DB.php is not actually a class, it's a function, so you won't be extending it, you'll be replacing it completely, but obviously, you won't be touching the core files. You'll just override the database() method in the Loader class with one that tells it to look in your libraries directory DB.php, where it will load your customised version which will have the code to send you Emails. However, whilst you should be able to load the Email class, you may not be able to. If that's the case, you might have to go the traditional route for sending an Email to yourself. You could add a function to DB.php and call it something like _email_db_error(), to avoid any name clashes with any future helpers.
#6

[eluser]Banana Man[/eluser]
I also noticed that no HTTP Status Codes are set in the DB_driver.php in closer inspection, so this could mean that if your site gets crawled whilst your having problems with a database connection you could in affect get it re-indexed with a page designated for errors instead of your content, as the status code is 200 (all is well) even if there are connection issues, is there a reason for this ?
#7

[eluser]Banana Man[/eluser]
Thanks for your reply, i'll look into it further
#8

[eluser]TheFuzzy0ne[/eluser]
On second thoughts, it will be better to extend the display_error() method in DB_driver.php. Again, you'll need to override the database() method in the Loader class, so it doesn't instantiate the normal DB_driver class, but just loads it, and instantiates you're class which extends it. More on extending database drivers can be found [url="http://codeigniter.com/wiki/Extending_Database_Drivers/"]here[/url].
#9

[eluser]Banana Man[/eluser]
BTW, for the HTTP Status issue, ive just added this line at the top of error_db.php

Code:
<?php header("HTTP/1.0 500 Internal Server Error");?>

error_db.php may also be an easier place to deal with emailing myself also
#10

[eluser]Banana Man[/eluser]
Thanks for the link, i'll try out a few different approaches.

Thanks for your time




Theme © iAndrew 2016 - Forum software by © MyBB