Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I check whether database host is valid?

  try {
     Yii::app()->db;
  } catch (Exception $ex) {
     echo $ex->getMessage();
  }

Code above gives me this error when I use invalid host address:

PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known.

I just want to receive something that returns false, so I could display my own error message

share|improve this question
do you have the arguments for the database in the right place? – jycr753 16 hours ago
yes I just used invalid host on purpose – Riso 16 hours ago
have you try mysql_ping ? – jycr753 16 hours ago
@jycr753 it says "mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known" when I tried to connect using mysql_connect, don't see anything helpful in link you provided – Riso 16 hours ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.