Programming Logics FORUMS

Full Version: How to Log MySQL Errors in PHP?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The complete code for this tutorial can be found at the bottom in the "tips" section.Create a junk MySQL query in your PHP file. I just put in random characters for the "user name" and "password" fields in the mysql_connect() statement. You should get an error similar to that shown in the image.The error shown may be good when you're developing, but you wouldn't want everyone to see what your user name and host name are. You could get hacked, and that's never a good thing. We also don't want to just silence all errors (@), since if there is an error we want to know what it is. So, we'll use a log file (in this case, log.txt). We're going to create a function called writeErrors().
I agree with you but with that We also need to update writeErrors function () to handle the new parameters and to create a complete error. When you insert an error in the PHP editor, \ n to use a new line, and add the contacts (if you want), so that the output is readable. At least every error at the end of \ n to distinguish the individual errors...
Reference URL's