0

This code gives an error.

  <?php
    class DbOperation
    {
        private $con;
        function __construct()
        {
            require_once dirname(__FILE__) . '/DbConnect.php';
            $db = new DbConnect();
            $this->con = $db->connect();
        }
        function UyingaKirish($data){
            function Tekshir($ki1){

                $stmt2=$this->con->prepare("SELECT HowManyPlayers FROM groups WHERE NumberOfGroup=?"); //error is here
                $stmt2->bind_param("i",$ki1);
                $stmt2->execute();
                $stmt2->store_result();
                return $ki1;
            }

$u=Tekshir(5);
    }

But when I use like this it works fine

class DbOperation
    {
        private $con;
        function __construct()
        {
            require_once dirname(__FILE__) . '/DbConnect.php';
            $db = new DbConnect();
            $this->con = $db->connect();
        }
        function UyingaKirish($data){
   $u=5;
                $stmt2=$this->con->prepare("SELECT HowManyPlayers FROM groups WHERE NumberOfGroup=?");
                $stmt2->bind_param("i",$u);
                $stmt2->execute();
                $stmt2->store_result();
    }

So the whole error is

Fatal error Using $this when not in object context in

How can use it inside the function?

Brutal
  • 798
  • 1
  • 14
  • 37
  • 3
    So, what's the point of having function __inside__ a function? – u_mulder Jun 19 '18 at 12:44
  • @u_mulder I have a lot function like this in my whole code. – Brutal Jun 19 '18 at 12:48
  • 1
    That's not an answer. – u_mulder Jun 19 '18 at 12:48
  • @u_mulder When I use first function I have to use second function multiple times and I have to set database values while I am getting another values. So I think functions inside function will be faster and readeble way for it. If you know the answer please help me – Brutal Jun 19 '18 at 13:01

0 Answers0