Forum Moderators: coopster
If I display an error it's a generic "there was a problem with the database" unless a constant DEBUG_MODE is set to true in which case the code outputs the actual error.
Welcome to WebmasterWorld, mimizzee.
Placing an @ in front of a function call suppresses error messages. Use it carefully; you can bewilder yourself if problems occur and you don't see the errors that are being generated.
>> but that would take a lot of time
ummm, yes it would but you can do something correctly, or not, whichever you like.
If you want a good practice for future projects
build in an error function that you can use instead of die() then you can have it echo mysql_error() while in dev. When you move it to live you can change it in a single spot and change to some type of logging.
I know I am over 40 days late here =P, but thank you all for replying to this thread. My question was really dumb anyway, I actually found a simple solution all by myself about a month ago, but forgot to report it here:
1. I created 1 new Constant and used quite a bit one constant I had already created:
- SITE_PATH (had created it a while ago already) = can be either "http://www.example.com/" or "http://localhost/". It will change depending on which server I am on (locally or just in my Web Hosting company's server).
- MY_IP = my own IP address, which never changes.
2. I created a new function in PHP called isLocalhost(). Basically it returns TRUE if the IP corresponds to my own IP address and if the SITE_PATH is equal to "localhost".
Since I have one simple PHP class called Query to perform any database functions, I changed one part of my code to the following simple IF statement to show errors ONLY IF I am visiting my site:
<?phpif (isLocalhost()) {
mysql_query($this->query) or die( mysql_error() );
} else {
mysql_query($this->query);
}?>
Where "$this->query" is the variable with my MySQL Query. Eg: "SELECT * FROM users".
It worked pretty well. I wrote a database query that did not make sense just to test whether the error would show up or not. And it did show up. I went to a Proxy website and visited my own site in it to see if the errors would show up, and as expected, they did not. So as you can see this is pretty straight forward.
Again, this is a pretty simple solution. It may take some time for some people to make the necessary changes, but if you have a PHP class Database abstraction layer like me, I'm sure it will be pretty easy to make this change in your code.
Hope this helps someone too.
Cosmoyoda