Eduardo Fuerte
asked on
How to treat the way PHP presents a DB error?
Hi Experts
During a DB actualization if a constraint is violated PHP presents an error directly related with DB itself in a not adequate manner to the final user, accordingly with the Picture:
The code used
Is it possible to treat this situation in a way that an alert only with the relevant part of the error (related to DB actualization) is presented?
Thanks in advance!
During a DB actualization if a constraint is violated PHP presents an error directly related with DB itself in a not adequate manner to the final user, accordingly with the Picture:
The code used
$sql = pg_query($comando);
if ($sql)
{
echo '<script>alert("You Have Successfully updated this Record!");</script>';
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Dados do orgao adicionados!!!</div>');
redirect('orgao/index', 'refresh');
}
else
{
//die( pg_result_error($sql));
//$erro = pg_result_error($sql);
echo '<script>alert("Orgao nao foi salvo!");</script>';
redirect('orgao/index', 'refresh');
}
redirect('orgao/index', 'refresh');
}
Is it possible to treat this situation in a way that an alert only with the relevant part of the error (related to DB actualization) is presented?
Thanks in advance!
ASKER
Hello
Thank you for the elaborated reply.
Before to go changing PHP.ini or .htaccess files I'd like to know if it doesn't have another alternative to try/ catch the exception and presents only the relevant part of the error message.
Thank you for the elaborated reply.
Before to go changing PHP.ini or .htaccess files I'd like to know if it doesn't have another alternative to try/ catch the exception and presents only the relevant part of the error message.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thnak you
In truth I'm going to better reflect on your reply later, but I think it is the way to solve.
In truth I'm going to better reflect on your reply later, but I think it is the way to solve.
It's not the only setting that should differ in the production vs development environment. See this php.ini section of the default php.ini:
In regard to errors display_errors and error_reporting are the two settings.
If you don't have access to the php.ini (because you are a typical shared hosting client) then the .htaccess files can help you control these settings for your site. For example a line like php_flag display_errors off.
Error messages displayed to non customers are not only user unfriendly, they also reveal too much details about your site and database.
As a more detailed reference look here: https://www.owasp.org/index.php/PHP_Configuration_Cheat_Sheet
Bye, Olaf.