简体   繁体   中英

prepared statement in php is returning 0 rows

I have a table with only one row called users in my database with email and mobile_number as it's columns.My row has that mobile_number column value as 9866163987.When I am trying to select this mobile number value my prepared statement is returning 0 rows.Here is my code.

if($this->checkExists("email",$_POST["registerEmail"]))
{
    --some code--
}
if($this->checkExists("mobile_number",$_POST["registerMobileNumber"]))
{
     --some code--
}
private function checkExists($field,$value)
{
    include("includes/connection.php");
    $sql = "SELECT $field FROM users WHERE $field=:value";      
    $prepare = $connection->prepare($sql);
    $prepare->bindParam(":value",$value,PDO::PARAM_STR);
    try
    {
        $prepare->execute();
    }       
    catch(PDOException $e)
    {           
        die($e->getMessage());
    }
    $count = count($prepare->fetchAll());
    echo $count."<br />";
    if($count == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

For email it is working fine and returning one row,but for mobile_number it is returning 0 rows?what to do?

Your interger is being truncated because it exceed the 32 bit limit of an int. (as @Mike Stotts said in the comments)

see What is the size of column of int(11) in mysql in bytes?

You could use a string instead or use something bigger like bigint.

Note: if you plan on using bigint, you should consider adding store_result(); before your bind_result to prevent memory exhaustion: See: PHP mysql_stmt::fetch() gives PHP Fatal error memory exhausted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM