-2

so this is my code:

<?php 

    class DB{

        private $host       = 'loscalhost';
        private $user       = 'root';
        private $password   = '';

        function __construct(){
            try {
                $connect_db = mysql_connect($this->host, $this->user, $this->password);
            }catch(Exception $e){
                echo 'DB connection failed: ',  var_dump($e), "\n";
            }
        }
}

I changed the host variable value so i can display the message DB connection failed..., but my question is why is it not displayed? instead i get this: Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known

Maria Muresan
  • 93
  • 1
  • 4
  • 12
  • try private $host = 'localhost'; – Rakesh Sharma Dec 26 '14 at 13:11
  • Please search for your problem first, this error message has even been asked and answered about. Additionally double check your code of typos as asking because of such little mistakes is off-topic. This works if you type the code you have a problem with as a new example with as little code as necessary to reproduce and from scratch (no copy and paste, not a single bit). – hakre Dec 26 '14 at 13:12
  • @hakre, my question is not about i mispelled the localhost – Maria Muresan Dec 26 '14 at 13:13
  • Then please make yourself comfortable with error reporting: http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting - you control this with your php.ini. If you see the message on a production server PHP is not configured correctly. Please see this reference question: [Remove warning messages in PHP](http://stackoverflow.com/q/1987579/367456) - Again, please use the search. – hakre Dec 26 '14 at 13:15
  • And sure, you get the error message because you misspelled localhost. That's the reason why you ask. If you had not mispelled it, you wouldn't ask. :) – hakre Dec 26 '14 at 13:17
  • I'm happy to see such an intellectual person as you are, hakre, your logic is the best :) – Maria Muresan Dec 26 '14 at 18:37

1 Answers1

1

Host name is localhost but you used loscalhost

 private $host = 'loscalhost';

should be

private $host = 'localhost';
MH2K9
  • 11,951
  • 7
  • 32
  • 49
  • please do not answer to questions that are obviously caused by a typo. additionally there is already a duplicate for this posting of an error message. – hakre Dec 26 '14 at 13:11