Functions.php file

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

The query function from mysql.php

 public function query($sql, $params=[]) { try { $sth = $this->db->prepare($sql); $sth->execute($params); return $sth->fetchAll(PDO::FETCH_OBJ); } catch (PDOException $e) { echo 'Ошбика при выполнение запроса: ' . $e->getMessage(); } } 

I check the function in index.php

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

And he just shows me:

array (0) {}

In the specified parameters, everything is correct, checked through phpMyAdmin there it finds.

SELECT * FROM users where email = 'qwe@mail.ru' AND password = MD5 ('123123')

Here is the screen:

Screen

I tried to change the SQL query to this:

$ sql = "SELECT * FROM users";

And I have everything brought out, brought all users. It turns out the problem is somewhere with the $ params array or something else, I can not understand ...

    2 answers 2

    : email and: password in sql query must be without quotes

     $sql = "SELECT * FROM users where `email` = :email AND `password` = :password"; 
    • Well, I didn’t have them from the beginning ... I just added them right now ... And then when I didn’t have them, I still didn’t work. And now you said to remove them, I removed and everything worked, what kind of magic ... Thanks. - cr1gger
    • Maybe the file on the server is not flooded or not saved. It happens. but must be without quotes. - Rochfort

    Maybe a problem with MD5?

    Your PHP request

    $ sql = "SELECT * FROM users where email = ': email' AND password = ': password'"

    But the phpmyadmin request:

    SELECT * FROM users where email = 'qwe@mail.ru' AND password = MD5 ('123123')

    try to remove md5 from the parameters and call inside the query:

    $ sql = "SELECT * FROM users where email =: email AND password = MD5 (: password)";

    Or check the simple request with one parameter for email