I have a table in the database, there is one field token

I get a token to the input and I have to compare it with the token that is in the database.

But the comparison for some reason, no, the answer from the server is the following: Result of strcmp (asda, 1) is 1

$token = $_GET["token"]; $stmt = $pdo->prepare("SELECT token FROM Tokens WHERE token =? LIMIT 1")->execute(array($token)); echo("Result of strcmp ($token , $stmt) is "); echo(strcmp ($token, $stmt)); if($stmt == $token ){ 
  • five
    We open the DOCUMENTATION and read execute - Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки. ....... back true , tobish 1 - Alexey Shimansky
  • 2
    I would say that fetch() or some numRows() was lost somewhere - ArchDemon
  • @ Alexey Shimansky and how to fix it?) - Martinez Toni
  • one
    @MartinezToni you need the value from the database, not the result of the execute operation. As written above: Values ​​are fetched through the fetch - Aleksey Shimansky
  • @ Alexey Shimansky is good, then if I write like this if ($ stmt == 1) {} - Martinez Toni

1 answer 1

Strcmp returns a negative number if str1 is less than str2; a positive number if str1 is greater than str2, and 0 if the strings are equal. I would rewrite $stmt = $pdo->prepare("SELECT token FROM Tokens WHERE token =? LIMIT 1")->execute(array($token)) to the classic style of working with sql queries to identify the error and figure out how to fix .