i want to pass connection link to a class. i try in such way but unable to get solution here dbconnect.php
<?php
global $con;
$db_host="localhost";
$db_username="root";
$db_pass="";
$db_name="xxx";
$con= mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysqli_select_db($con,$db_name) or die ("no database");
?>
and my class php file
<?php
include('dbconnect.php');
$chechout=new clscheckout;
$chechout->con=$con; // direct assign connection link
$chechout->adult_count=2;
$chechout->child_count=1;
$chechout->child_cwb_count=1;
$chechout->setConn(); // assign throug function
echo $chechout->fnTotel();
class clscheckout{
public $pack_id;
public $pack_title;
public $user_id;
public $adult_count;
public $child_count;
public $child_cwb_count;
public $con;
function setConn ($conn) {
$con=$conn;
}
function fnTotel () {
$qry='select * from package where pack_id='.$pack_id ;
$rs=mysqli_query($con,$qry);
if($rs)
{
$row=mysqli_fetch_array($rs);
$child_wob_price=$row['child_wob_price'];
$adult_price=$row['adult_price'];
$child_price=$row['child_price'];
}
$adult_total=$adult_price*$adult_count;
$chidl_total=$child_price*$child_count;
$child_wob_total=$child_wob_price*$child_cwb_count;
return $adult_total+$chidl_total+$child_wob_total;
}
}
?>
I assign the like in both directly and through function. but no get successfull