0
mail('some@email.com',$subject,'Beginning');
$db_connection = mysqli_connect('myremote.host.com','username','password','db_name');
mail('some@email.com',$subject,'Connected');

if (mysqli_connect_errno())
{
echo mysqli_connect_error();
mail('some@eail.com',$subject,'Error in Connection');
exit();

}

I am trying to connect to this database. I use mail() as a way to debug. I get the first mail "Beginning" but I can't get the mail "connected".

The same code I used in one of my other pages and it works fine. Why I can't get it to work on this page ? what am I doing wrong ?

AirForce
  • 83
  • 1
  • 1
  • 5
  • 1
    I don't think I've ever seen somebody using `mail()` as a debug tool... That is wrong on so many levels. – scrowler Aug 07 '14 at 21:43
  • I've removed your email address and database connection information from your post, best not to post actual info like that. – scrowler Aug 07 '14 at 21:47
  • Can you suggest any good debugging tools ? – AirForce Aug 07 '14 at 21:50
  • How about using the error messages of mysqli? Have a look at the examples on [mysqli::error](http://www.php.net/manual/en/mysqli.error.php) – VMai Aug 07 '14 at 21:52
  • `die(var_dump($db_connection));` should do the trick. The result of your DB connection is stored in `$db_connection`. – scrowler Aug 07 '14 at 21:52
  • try this answer - http://stackoverflow.com/questions/9836693/how-to-use-throw-exception-in-mysql-database-connect – Mike Aug 07 '14 at 21:53
  • I use mysqli error messages. I don't get any reply. – AirForce Aug 07 '14 at 21:56
  • I tried using or die. When I use it I stop getting emails at all. even the very first one before executing other code. – AirForce Aug 07 '14 at 21:58
  • AirForce - don't rely on emails to do your debugging. Do it in the browser, or if you're using command line - rely on output from that. Emails depend on multiple servers to come through and you aren't actually using the result of your DB connection to determine what to send in your email - my main point here is stop using emails for debugging. – scrowler Aug 10 '14 at 23:16

0 Answers0