Functions.php file

include __DIR__ . "/mysql.php"; $mysql = new Mysql(); function checkPassword($pass, $email){ $sql = "SELECT * FROM user where `email` = :email AND `password` = :password"; $params = [':email' => $email, ':password' => md5($pass)]; //var_dump($params); var_dump($mysql->query($sql, $params)); } 

The query function from mysql.php

 public function query($sql, $params=[]) { $sth = $this->db->prepare($sql); $sth->execute($params); return $sth->fetchAll(PDO::FETCH_OBJ); } 

I check the function in index.php

 include(__DIR__. '/core/functions.php'); checkPassword('123123','qwe@mail.ru'); 

And I have such a mistake.

Fatal error: Call to a member function query () on null in E: \ OpenServer \ OpenServer \ domains \ blackmarket \ core \ functions.php on line 9

I can not understand what is wrong ?! All variables are not empty, that he does not like that ((

    1 answer 1

    Well, it's all about the scope of variables. read docks

    • What is wrong with visibility? I pass the values ​​of the variables in the parameters of the function, and use them inside the function ... What's wrong? - cr1gger
    • The $mysql object inside the checkPassword function checkPassword you pass? Have you even opened the link that I gave you? There is literally the second paragraph your code is being sorted out - Rochfort
    • I figured out thanks. I did not see the link at first ... - cr1gger