Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Função PHP para extrair um valor de campo de um banco de dados


Tente isso
function selectUserField($email, $field, $connection){
    $select_user = "SELECT `$field` FROM users WHERE `email`='$email' LIMIT 1"; //wrap it with ` around the field or don't wrap with anything at all
    $result = mysqli_query($connection, $select_user);
    $value = mysqli_fetch_assoc($result);
    return $value[$field];
}

//And I try to echo the result of the function
$connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

echo selectUserField("[email protected]", "name", $connection);