When i prepare the $sql, i got error "Notice: Undefined variable: obj in.."
member.php
<?php   
require_once('database.php');
$obj = new Database;
$obj->getConnection();
class Member{
private $username;
private $userpassword;
public function regist(){
if(isset($_POST['action'])&&$_POST['action']=='insert'){
try{
    $sql = "INSERT INTO userData(username,password)VALUES(:username,:password)";
    $stmh = $obj->prepare($sql);//the error occour here
    $stmh -> bindValue('username',$_POST['username'],PDO::PARAM_STR);
    $stmh -> bindValue('password',password_hash($_POST['userpassword'],PASSWORD_DEFAULT),PDO::PARAM_STR);
    $stmh -> execute();
    echo "登録しました<br>";
        }catch(PDOExcetion $e){
            echo "error ".$e->getMessage();
        }
    }
}
public function login(){
    $sql = "SELECT * FROM userData WHERE username=:usrname";
    $stmh =$obj->prepare($sql);//the error occour here
    $stmh ->bindValue(':usrname',$_POST['username'],PDO::PARAM_STR);
    $stmh->execute();
    $row = $stmh->fetch(PDO::FETCH_ASSOC);
    if($row['username'] == false){
        echo"login fail";
        exit;
    }
    $hash = $row['password'];
    if (false === password_verify($_POST['userpassword'],$hash)){
        echo"login fail";
        exit;
    }
   }
}
database.php
i just create Database class, i want to use $pdo which is protected, so i create getConnection() function and return the $pdo. So what i think is i just create a object like $obj=new Database(); $obj->getConnection(); then i can access $pdo variable.But it doesn't work. The error occur at above "member.php". please help
<?php
class Database{
protected $pdo;
public function __construct()
{
    $this->db_connect();
}
private function db_connect()
{
    $servername = "localhost";
    $username = "abc";
    $password = "abc";
    $dbname = "mydb";
    try
    {
      $this->pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      $this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
      $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
    }catch(PDOException $e)
        {
        die("error connection ".$e->getMessage());
        }
}
public function getConnection()
{   
    return $this->pdo;
}   
  }
  ?>
 
    