My code is like this:
<?php
define("ERROR", "SOMETHING WRONG WITH MY DATABASE");
...
if (!mysql_query($q)){
die(ERROR);
}
?>
Now I want to replace “SOMETHING WRONG WITH MY DATABASE” with mysql_error() in case I want to debug it. what is the easiest way ?
This does not seem to work work: define("ERROR", mysql_error());
—- edit —
I don’t want to use mysql_error() under production environment, it may help the attacker figure out something related to my database? That’s my point of using a constant string
as in C you can do
#define x yourfunction()
I’m not sure if I can do the same in php
The simple answer is “you cannot do that”. The whole point of constant is that it’s constant as in its value is never changed. If it refers to a function call, the function can return any value – and it’s not constant any more.
One trick you can do is define the function call itself to be the value of the constant – and then
evalit on demand, something like this:However this is really a rather bad code. You’d be much better off doing