0

I've been working for the past hour on this one prepared statement.

It returns 0 for the num_rows every time.

I've run the query through my database manually in phpmyadmin and there's nothing wrong with it. And $user_id is set fine as well.

if ($statement = $mysqli->prepare("SELECT google_id FROM google_users WHERE google_id = ? LIMIT 1"))
{
    $statement->bind_param("i", $user_id);
    $statement->execute();
    $statement->store_result();
    if ($statement->num_rows < 1)
    {
        $alerts .= '<div class="alert alert-danger" role="alert">Your login session was not valid. Please log in again.</div>';
    }
    $statement->free_result();
    $statement->close();
}
sjas
  • 18,644
  • 14
  • 87
  • 92
Amy Neville
  • 10,067
  • 13
  • 58
  • 94
  • Are there any results then? – Jite Jun 27 '15 at 15:36
  • @Jite when I run it through the database it returns a google_id as expected – Amy Neville Jun 27 '15 at 15:38
  • 1
    Is the google_id stored as a int or string in the database? – Jite Jun 27 '15 at 15:38
  • Currently decimal(21,0)....hmmm you might be onto something...what does this mean? – Amy Neville Jun 27 '15 at 15:39
  • 1
    I'd echo the `$user_id` value and check so that its correct (could be that php cuts it of if its too big, it could be a larger number than a 64b int allows, its a google id, they quite long). Also, try change the `i` in the `bind_param` call to a `d`. – Jite Jun 27 '15 at 15:43
  • just tried all those things - still nothing - the $user id was stored fine I echoed it out to check – Amy Neville Jun 27 '15 at 15:46
  • I changed the google_id field to an int(30) now.....still same problem with the above code – Amy Neville Jun 27 '15 at 15:56
  • The value you set `INT` to in mysql is not the size of the integer, but the size of the column in the ui. `BIGINT` would probably be the closest you could get (which might still be too small), I would personally use a string for this (`varchar(255)`, in the varchar case, the value is actually the max number of chars). – Jite Jun 27 '15 at 15:58
  • I put it back to decimal(21,0) works fine.....just doesn't carry out the query as expected... – Amy Neville Jun 27 '15 at 16:19
  • ok I solved it....answer was I had to do: $statement->bind_param("i", $user_id); never occurred to me that a decimal had to be binded as a string in mysqli... – Amy Neville Jun 27 '15 at 16:21

0 Answers0