CodeIgniter Forums
Prevent connection errors to pop up ... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Prevent connection errors to pop up ... (/thread-55185.html)



Prevent connection errors to pop up ... - El Forum - 10-13-2012

[eluser]Sven Delle[/eluser]
I'm checking for a connection with (yes, I know it's not properly escaped):

Code:
$db_conn = new mysqli($this->input->post('host'), $this->input->post('mysql_admin'), $this->input->post('mysql_password'));
  
  if ($db_conn->connect_errno)
  {
   return false;
  }
  else
  {
   return true;
  }

I'm retreving the result in another function which is supposed to handle the different views. But when the connection fails, due to wrong credentials, I get PHP errors popping up in the view.

Code:
Message: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'blabla'@'blabla' (using password: YES)

How do I avoid that, and handle them myself?

And I'm looking for a non specific server solution, as I'll be running this on various servers over which I have no control. So I'm not looking for error_reporting reconfigurations.


Prevent connection errors to pop up ... - El Forum - 10-13-2012

[eluser]Sven Delle[/eluser]
I tried with a try / catch routine. But it still gave med PHP errors in the views. So I ended up adding a @ before new mysqli ... but it stills seems like a hack of sorts.