I've done a recipe_book with PDO, but not in an object oriented way. Now, I have to do it using objects.. (I do not have much experience with PHP in an object oriented way).
Basically, I am just trying to create my Connection class, but I guess I am doing something wrong, because I can not check that it has been successfully.
This is my Connection.php:
<?php
class Connection {
protected $db_host;
protected $db_user;
protected $db_pass;
protected $db_name;
protected $db_driver;
private $conn;
function __construct() {
$this->db_host = 'localhost';
$this->db_user = 'someuser';
$this->db_pass = 'somepass';
$this->db_name = 'somedatabase';
$this->db_driver = 'mysql';
try {
$this->conn = new PDO($this->db_driver . ":dbname=" . $this->db_name . ";host=" . $this->db_host, $this->db_user, $this->db_pass);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Connected Successfully';
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$this->conn = $conn;
}
//ends __construct
}
I am not sure, what the __construct method should include as arguments.... and as much I look on other posts, more messed up it is in my mind. I can't see what I am doing wrong. What I am expecting, is, that is the connection is successful, if I access on the browser to this Connection.php file, it's too see echoed "Connected Successfully", but instead, I see nothing, just white page, and I don't know if I am doing something wrong.... or maybe I am expecting something wrong...
Could someone tell me how can I check that the connection has been created successfully?
Thank you