num_rows不工作pdo,mysqli,总是返回0

I have a interesting problem.

// in pdo with function --> not work

function UserIsExist($name)
{
    global $db;
    $stmt = $db->prepare("SELECT id FROM tarskereso_users WHERE email = '$name' LIMIT 1");
        $stmt->execute();
        if ($stmt->fetchColumn() == 1) return 1;
        else return 0;
}

// with MySQLi --> not working

function UserIsExist($name)
{
    global $db;
    $stmt = $db->prepare("SELECT id,email FROM tarskereso_users WHERE email = ? LIMIT 1");
        $stmt->bind_param('s', $name);
        $stmt->execute();
        $stmt->store_result();
        if ($stmt->num_rows == 1) 
            return 1;
        else 
            return 0;
        $stmt->close();
}

// In Register.php

 ... other ..
        if(UserIsExist($user) == 1)
            $error_msg = "Is Exist";
        else
        {
            $birthdate = $year.'.'.$month.'.'.$day;
            CreateUser($user,$pass,$birthdate,$sex);
                $error_msg = 'Success';
        }

So, with function not working, I try with:

$stmt = $db->prepare("SELECT id,email FROM tarskereso_users WHERE email = ? LIMIT 1");
        $stmt->bind_param('s', $name);
        $stmt->execute();
        $stmt->store_result();

        if ($stmt->num_rows > 0) 
            ... other ...
        else 
            echo 'isnt exist...';
        $stmt->close();

but not working, the num_rows always return 0. And the account in the database successfuly created

in pdo, num_rows won't work. you have to use $sql->rowCount() method to get number of records in a table.

<?php
    $sql = $con->prepare("<YOUR SQL QUERY HERE>");
    $sql->execute();
    if($sql->rowCount() > 0){
        echo $sql->rowCount() ." rows found";
    }
?>