Coolen Coolen - 6 months ago 17
PHP Question

query met num_rows, bind_param and fetch_assoc

In this combination of num_rows, bind_param en fetch(_assoc).

I don't get any results in $salt = $saltuitkomst['salt'];

$user = 195

$rows is giving the number 1 as a result

No error messages

$saltqry = "SELECT
salt,
mw_gegevens_groep
FROM
mw_gegevens
WHERE
mw_gegevens_persnr = ?
";
if(!$statement = $connection->prepare($saltqry))
{
echo "Query error:.". $connection->error();
} else {
if(!$statement->bind_param('i', $user)){
echo "bind param did not work";
}else{
$statement->execute();
$statement->store_result();
$rows = $statement->num_rows;
$saltuitkomst = $statement->fetch();
}
}
if($rows == 0) {
$salt='';
} else {
$salt = $saltuitkomst['salt'];
echo '-'.$salt.'-';
}

Answer
$saltqry = "SELECT
                    salt,
                    mw_gegevens_groep
            FROM 
                    mw_gegevens
            WHERE   
                    mw_gegevens_persnr = ?
            ";
            if(!$statement = $connection->prepare($saltqry))
            {
            echo "Query error:.". $connection->error();
            } else { 
                if(!$statement->bind_param('i', $user)){
                echo "bind param did not work";
                }else{
                $statement->execute();
                $statement->store_result();
                $statement->bind_result($salt, $group); 
                $saltuitkomst = $statement->fetch();
                if($saltuitkomst) {
                   echo '-'.$salt.'-';
                } else {
                   $salt='';
                }
                $statement->close();
                }
        }