CodeIgniter Forums
Error control operators in mysql_driver? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Error control operators in mysql_driver? (/showthread.php?tid=50238)



Error control operators in mysql_driver? - El Forum - 03-20-2012

[eluser]ashiina[/eluser]
I'm constantly having trouble dealing with Mysql errors.
Things such as
* php-mysql library load error
* DB Connection error
* Query syntax error
are all being suppressed with the "@" operator, like as follows:

Code:
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
...
return @mysql_query($sql, $this->conn_id);

I believe that they should ideally all be caught and outputted in some way,
so that developers don't have to wonder where their error is occurring.

My simple solution would be to remove the "@" operators so that
the errors will at least appear in your server log (and that's what I'm doing in my app),
but is there a problem with that?



Error control operators in mysql_driver? - El Forum - 03-20-2012

[eluser]ashiina[/eluser]
I read somewhere in the past discussions that
the try-catch cannot be used due to PHP4 support,
but my view is that suppressing the error is not the answer.

I'm still new to the community and would like to know
what others are feeling (and also if there already is an ongoing thread about this).


Error control operators in mysql_driver? - El Forum - 03-20-2012

[eluser]InsiteFX[/eluser]
You can use try / catch, the only thing is that CodeIgniter creates it's own Exception Handler.



Error control operators in mysql_driver? - El Forum - 03-20-2012

[eluser]ashiina[/eluser]
Hi InsiteFX

Thanks for your reply.
Yes, I also believe that people having trouble can individually write their try-catch-throw blocks.
(Although I was too lazy to do that in my personal app...)

What I want to hear people's opinions about, is
"What is the best thing which CodeIgniter should do with these DB errors, while maintaining PHP4 support?".
If we can come up with a good solution,
it'd be great if we can actually implement a fix into the CodeIgniter project.

*And my proposal was the primitive approach of just letting PHP spit out its errors.