Hello,
I'm using below PDO connection class
but didn't shows any result , Pls reply if u found any bugs..-
//name connect.class.php
class Connection {
private $connection;
private $username;
private $password;
private $dsn;
/**
* To connect to another database, change the "mysql" in the dsn attribute to
* the database you want.
* for example: pgsql:dbname...
*/
public function __construct() {
$this->dsn = "mysql:host=localhost;dbname=example";
$this->username = "root";
$this->password = "root";
}
public function setConnection($conn) {
$this->connection = $conn;
}
public function getConnection() {
return $this->connection;
}
public function connect() {
$pdoConnect = new PDO($this->dsn, $this->username, $this->password);
$this->connection = $pdoConnect;
}
}
//connection class call in index.php
<?php
include("connect.class.php");
$conn= new Connection();
$db=$conn->connect();
if (!$db)
{ echo "Fail"; }
else {echo "Connect";}
?>