PHP oops and Mysql
Example 1:- In this example we fetch DataBase Record through oops concepts.

<?php
class DB
{

var $queryresult;

function DB()
{
mysql_connect(\'localhost\',\'root\',\'\') or die(\"Mysql not connected\");
mysql_select_db(\'newportal\') or die(\"Database not connected\");
}


function query($query)
{
$this->queryresult = mysql_query($query);
return $this->queryresult;
}


function fetchNextObject($result)
{
return mysql_fetch_object($result);
}

}


$obj=new DB();

$query=\"select * from new_story\";

$sql=$obj->query($query);

while($line=$obj->fetchNextObject($sql))
{
echo $line->new_heading.\"<br>\";
}

?>


Previous