How to access the result of a SELECT EXISTS query? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, February 17, 2022

How to access the result of a SELECT EXISTS query?

I slightly modified the Select Exists function that I found on a stackoverflow answer. How do I access the result of the EXISTS query?

function uniqueexists($dbHandle,$tablename,$fieldname='username',$value) {
    $sql = 'SELECT EXISTS(SELECT * FROM `'.$tablename.'` WHERE `'.$fieldname.'` = ? LIMIT 1)';
    $stmt = mysqli_prepare($dbHandle, $sql);
    mysqli_stmt_bind_param($stmt, 's',$value);  
    $sqlResult = mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    
    $exists = ... // How to use the $sqlResult or the $result? ...

    return $exists;
}

With: username Index varchar(255) utf8_german2_ci
The fieldname's entries are set to unique.



source https://stackoverflow.com/questions/71147352/how-to-access-the-result-of-a-select-exists-query

No comments:

Post a Comment