-1

my function returns always false an i dont know why... my usage is i guess right of the function. I looked in the logs for errors but there are no errors. I am using the pdo library for my mysql requests

here is my function i used

function getUser($id){
    $db = Database::connect();
    $stmt = $db->prepare("SELECT * FROM user WHERE id = :id");
    $stmt->execute(["id" => $id]);
    return $stmt->fetch(PDO::FETCH_ASSOC);
}

thx for help

F.Ghost
  • 31
  • 7
  • 1
    https://www.php.net/manual/en/pdostatement.fetch.php says _"In all cases, false is returned on failure or if there are no more rows"_ . If PDO's error mode is on (see [here](https://www.php.net/manual/en/pdo.error-handling.php) for details) then you'd know about a failure anyway because there'd be an exception. https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-U says `user` is a reserved word, so you probably need to put that in backticks. If you turn on PDO error mode (along with PHP's general error reporting) it might tell you about the problem in more detail. – ADyson Jun 01 '22 at 13:51
  • If still no errors after that, then most likely the query simply returned no rows. Why that might be, we can't tell you because we cannot see the value you used in `$id` and we cannot see any sample data from your database, so we don't know if your query would match anything or not. – ADyson Jun 01 '22 at 13:52
  • @ADyson as far as i can see, there is no (R) next to USER, so it shouldn't be a reserved word – Your Common Sense Jun 01 '22 at 14:11
  • @YourCommonSense apologies, i stand corrected, was too hasty – ADyson Jun 01 '22 at 14:26

0 Answers0