为什么连接类不进行连接? [重复]

This question already has an answer here:

I am new to OOP and PHP, so I have a problem here. Could someone tell me, what I am doing wrong with my connection class? It does not connecting to the database, I've tried to var_dump($this) in try statement and it either doesn't work. Also I am changing my 'dbname' to a random name and the code still 'works'..

Here is my code:

<?php
    class connection {
        // Setting Database Source Name (DSN)
        public function __construct() {
            $dsn = 'mysql:host=localhost;dbname=employee';
            // Setting options
            $options = array (PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
            // Making the connection to the database
            try {
                $this->dbh = new PDO($dsn, 'root', '', $options); 
            }
            catch (PDOException $e) {
                $this->error = $e->getMessage();
            }
        }
    }
    $connection = new connection();
?>
</div>

Every method in class has to return something. Try:

  class Connection {

   private $connection;    
    // Setting Database Source Name (DSN)
    public function __construct() {
        $dsn = 'mysql:host=localhost;dbname=employee';
        // Setting options
        $options = array (PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
        // Making the connection to the database
        try {
            $this->connection = new PDO($dsn, 'root', '', $options); 
        }
        catch (PDOException $e) {
            $this->error = $e->getMessage();
        }
    }

    public function DoSomething()
    {
         //do something with your $this->connection and return some value;
    }
}
$connection = new Connection();
echo $connection->DoSomething();