-1

I have used below class for connection.

class createConnection //create a class for make connection
{
    var $host="localhost";
    var $username="root";    // specify the sever details for mysql
    var $password="";
    var $database="quiz";
    var $myconn;

    function _construct() 
    {
        $conn = mysqli_connect($this->host,$this->username,$this->password,$this->database);

        if(!$conn)// testing the connection
        {
            die ("Cannot connect to the database");
        }

        else
        {
            $this->myconn = $conn;
        }

        return $this->myconn;
    }

    function returnQuery($query) // call procedure
    {
        if ($result = mysqli_query($this->myconn ,$query) or die(mysqli_error($this->myconn))) {
          return $result;
        }
        else {
          return '0';
        }
    }

}

Now, I want to call returnQuery() function from another class like below-

 require('connect.inc.php');

class QCategory{

  private $link;
  public function _constuct()
  {
      $this->link = new createConnection();
  }

  public function GetParentCategoryList() {
            $query = "CALL GetParentQCategoryList()";
            if ($result = $this->link->returnQuery($query)) {
              return $result;
            }
            else {
              return '0';
            }

    }
}

but error ocurred like below - Fatal error: Call to a member function returnQuery() on a non-object in C:\wamp\www\quiz\include\qcategory.php on line 5

Help me as soon as posible!

pka246
  • 193
  • 10
  • 1
    `_constuct` is never called, because it's not the proper identifier for the constructor. – mario Jan 11 '14 at 12:53
  • 1
    Please do not add phrases like "Help me as soon as posible!" to your question. People are more likely to giver quicker and better answers if the question itself is clear. See [how to ask](http://stackoverflow.com/help/how-to-ask) for more information. – Sumurai8 Jan 11 '14 at 13:06

1 Answers1

0

In connect.inc.php and Qcategory class, change

function __construct(){ //an extra underscore.
Mohammed Ashiq
  • 468
  • 4
  • 18