Class Database { public $db; public $name = "root"; public $dsn = "mysql:host=localhost;dbname=Users;charset=UTF-8"; public $password = ""; public function __construct() { $this->db = new PDO($this->dsn, $this->name, $this->password); } public function find_login($login) { $sql = $this->db->query('SELECT login FROM Users WHERE login = {$login}'); return $sql->rowCount(); } public function find_mail($mail) { $sql = $this->db->query('SELECT login FROM Users WHERE mail = {$mail}'); return $sql->rowCount(); } } 

Fatal error: CallCount () on a non-object in C: \ OpenServer \ domains \ hosting \ Database.php on line 16

In a separate file without properties and methods, everything worked, but here the same error is that it is not an object. As a result, I need to get the number of affected columns or the result itself as a fact. Tried it through $sql->fetch() , the same error.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

so

 $sql = $this->db->prepare('SELECT login FROM Users WHERE login = :login'); $sql->execute(array('login'=>$login)); return $sql->rowCount(); 
  • But it works like a clock. Thank you very much! - Pavel Shklyaev

charset = UTF-8 on charset = utf8 Try to change, I had an error because of this

  • No, the matter is definitely not in it, I remembered with mysqli that they write it together in the database, but here I tried various options. - Pavel Shklyaev
  • Look at 1 answer and try, I fixed everything: D - Mikhail Lobanov