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();
?>