Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
致命错误:在php oop中调用成员函数prepare()_Php_Oop_Prepared Statement - Fatal编程技术网

致命错误:在php oop中调用成员函数prepare()

致命错误:在php oop中调用成员函数prepare(),php,oop,prepared-statement,Php,Oop,Prepared Statement,现在我学习使用OOP概念创建PHP crud操作 在这段代码中,我遇到了一些问题 Config.php Modules.php 如果在子类中定义构造函数,则必须显式调用父构造函数,因为它们不会自动调用 您必须在LoginContoller类中调用父构造 class LoginController extends CrudController{ public $emailID; function __construct($email){ $this->em

现在我学习使用OOP概念创建PHP crud操作

在这段代码中,我遇到了一些问题

Config.php

Modules.php
如果在子类中定义构造函数,则必须显式调用父构造函数,因为它们不会自动调用

您必须在LoginContoller类中调用父构造

class LoginController extends CrudController{
    public $emailID;
    function __construct($email){
        $this->emailID = $email;
        parent::__construct(); //explicit call to parent constructor
    }
    function userLogin(){
        $data = $this->sqlSelect("users" , "email = '".$this->emailID."'");
        return $data;
    }
}     
<?php
include_once("config.php");

class CrudController extends Database{
    function sqlSelect($TblName , $Condition){
        try{
            $query = "SELECT * FROM `xtratuition`.$TblName WHERE $Condition";
            $result = $this->db->prepare($query);
            $result->execute();
            $data = array();
            while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
                $data[] = $row;
            }
            return $data;
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }
}
class LoginController extends CrudController{
    public $emailID;
    function __construct($email){
        $this->emailID = $email;
    }
    function userLogin(){
        $data = $this->sqlSelect("users" , "email = '".$this->emailID."'");
        return $data;
    }
}

// This is works well

// $login = new CrudController();
// $data = $login->sqlSelect("`users`" , "email = 'klakshmanan48@gmail.com'");
// print_r($data);


$login = new LoginController("klakshmanan48@gmail.com");
$data = $login->userLogin();
print_r($data);


?>
class LoginController extends CrudController{
    public $emailID;
    function __construct($email){
        $this->emailID = $email;
        parent::__construct(); //explicit call to parent constructor
    }
    function userLogin(){
        $data = $this->sqlSelect("users" , "email = '".$this->emailID."'");
        return $data;
    }
}