I'm new to PDO and PHP. Can someone tell me what's wrong in my code. There is no error on browser it only shows (Connection Failed).
<?php
class Connect
{
private $host = "localhost";
private $user = "root";
private $password = "";
private $database = "srs_electrical";
private $dsn;
public $con;
public $stmt;
function __construct()
{
try
{
$this->dsn = 'mysql:host = ' . $this->host . ';dbname = ' . $this->database;
$this->con = new PDO($this->dsn, $this->user, $this->password);
$this->con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->stmt = $this->con->prepare("INSERT INTO comp_users VALUES(NULL,'Name','Email','Password')");
$this->stmt->execute();
echo 'connected';
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
}
}
$con = new Connect();
?>