Pregunta

Currently my codes look like this:

Query 1 or die(debug(mysql->error));
Query 2 or die(debug(mysql->error));
Query 3 or die(debug(mysql->error));
Query 4 or die(debug(mysql->error));
Query 5 or die(debug(mysql->error));

function debug(x)
{
  echo 'The error is' x;
}

The benifit is at any time if I want to remove debug messages in my website I just comment 1 line in debug function.

My questions are

  1. Is it good to use die? if die get called at Query 3, do the Query 4,Query 5 will get executed?
  2. Is that the best approach?
¿Fue útil?

Solución

1-Is it good to use die? if die get called at Query 3, do the Query 4,Query 5 will get executed?

No. die() means the script would stop. Simply stop and deliver the error.

2-Is that the best approach?

Yes. It's an approach I love to use.

However it's all well only in the development stages, and it ruins user experience by breaking the page and even giving mysql errors.

If your site is live, better learn how to use error handling and give your users an error they'd understand. Here is a nice tutorial.

Read die().

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top