user116032 user116032 - 2 years ago 77
MySQL Question

so how do you use mysqli $driver->report_mode?

I'm trying my newbie best to put together a production quality website. So I regularly use

$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL;

That may, or may not, be the thing to do. It helps me find things that just aren't quite 100%. But there seems to be this index thing that I can not rid myself of. The errors, even thou I use a try/catch poop on the net and wreck my header. The site then dies with messages no user would understand.. I don't understand.

My question is this. Among you that really maintain production sites, what do you do with the mysql driver? Do you set it to MYSQLI_REPORT_OFF, which seems to work just find ... or what?

I'm not trying to be insulting here (god knows I'm not lord of php/mysqli) but I'd really like to know what you pros do.

Thanks. (and if this gets cut for superfluous... I tried grace)

Answer Source

If I understand correctly, you want to create a great "Final Product" website that works perfectly and that, in the end, is the focus of all us developers with the sites we work on.

As you can see, the documentation for mysqli->report_mode method reads:

A function helpful in improving queries during code development and testing.

While your intentions are well meant, this function is not for production purposes because, as you very well point out, it writes text that causes headers to not be handled properly.

While on the end product, you don't even need to call it at all, what you have to do is to evaluate the return value of every method called on your project.

For example, if you want to run a query and check for errors, you would do:

if (!$mysqli->query("QUERY CODE")) {
  // error handling code here


// just for explanation purposes, this syntax is highly discouraged
if ($mysqli->query("QUERY CODE") === false)
  // error handling code here

On a production website (ideally) there should be no instances in which a query should not be completed successfully, but you should always evaluate to at least log the error on a file for future bug fixing and to alert the user in an elegant manner that there was an error that will be handled by the web master as opposed of showing them a white block above the layout of your site displaying code and paths that the user not only not understands, but that he/she doesn't care about, but that an evil user might take advantage of.

Also in a finished product, turn off all errors on screen and have them logged in files, not only queries but any other error that might arise.

While in the development stage anything goes, just make sure your site runs smoothly even with all errors turned on before turning them off and shipping it out.

I hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download