Call to a member function query() on null

前端 未结 1 1413
南方客
南方客 2021-01-24 01:03

I am new to programming in PHP and I\'m making a PHP class that receives queries but when summoned gives me the error \"PHP Fatal error: Call to a member function query () on nu

相关标签:
1条回答
  • 2021-01-24 01:24

    Your variable scopes are wrong. Try this:

    function conectarDB($svrName, $user, $pwd,$dbName){
        $this->conexion = mysqli_connect($svrName, $user, $pwd,$dbName); 
        return $this->conexion;
    }
    
    function consultaDB($consult){
        $result = $this->conexion->query($consult);
        return $result;     
    }
    
    0 讨论(0)
提交回复
热议问题