<?php
class Demo
{
var $con;
function __construct() //contructor
{
$this->con=new mysqli('localhost','root','',' php');
if(!$this->con)
echo "Connection Failed";
}
function setData($sql)
{
if($this->con->query($sql))
{
echo "Data inserted";
}
}
function getData()
{
$result=$this->con->query(" select * from tbl_demo");
while($row=$result->fetch_ assoc())
{
echo $row['fname']." ".$row['lname']."<br>";
}
}
}
class Demo2 extends Demo
{
}
$a=new Demo();
$b=new Demo2();
$sql="insert into tbl_demo (fname,lname) values ('ramesh','suresh')";
//$a->setData($sql); //Insert Data
//$a->getData(); //get data using parent class
$b->getData(); //get data using child class
?>
Comments
Post a Comment