PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$link = mssql_connect( $d["db_ip"], $d["db_un"], $d["db_pw"]) or die ("<p>Could not connect to the database. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>");
mssql_select_db( $d["db_db"], $link) or die ("<p>Could not select the database. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>");
?>
As you can see it currently just displays text. Is there any way to do that AS WELL AS send me an email notifying me the connection is dead? If so can you provide a code snippet. Thanks!
You can also do it by writing your own custom error handler. Here is a copy of ours, we just include this on every page. It gives us info abour the user and the last query that was ran. Also no need to add special code to each call.
If it's on the production site it mails us and gives a nice message to the user, if it's on the test system it just displays the error to the screen.
Ok, so I tried the first solution but it did not send me an email. And I know sendmail is fine becauase I have it working in other areas of the site. here is the entire function in case there is something in there scerwing this up.
<?php
function getDbByKey( $dbkey ) {
global $link;
global $arr_db;
$d=$arr_db[ $dbkey ];
if ( !is_array( $d ) ) {
die("<p>Could not select the database [$dbkey]. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>" );
}
$link = mssql_connect( $d["db_ip"], $d["db_un"], $d["db_pw"]) or die ("<p>Could not connect to the database. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>");
if (!$link) mail("tdelobe@usta.org","Insert Subject Here", "Insert Email Body Here");
mssql_select_db( $d["db_db"], $link) or die ("<p>Could not select the database. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>");
$result = mssql_query("set textsize 65000", $link);
}
?>
$link = mssql_connect( $d["db_ip"], $d["db_un"], $d["db_pw"]) or die ("<p>Could not connect to the database. If this problem is frequent, kindly notify <a href=mailto:webmaster@usta.org>webmaster@usta.org</a></p><br>");