Mysql PDO connection using Class

mysql pdo connection using class

class DatabaseConnection

	private $host = 'localhost';
	private $dbname = 'Demo';
	private  $username = 'root';
	private  $password ='';

    public $con = null;

    function __construct(){


    function connect(){


            $this->con = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->username, $this->password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

        }catch(PDOException $e){

            echo 'connection problem'.$e->getMessage();


$dbobj=new DatabaseConnection();

12 Replies to “Mysql PDO connection using Class”

Leave a Reply

Your email address will not be published. Required fields are marked *