Since the complañero answered with an example in PDO when you use MySQLi, I will leave this answer with an example in MySQLi.
The first thing you can see in this response from A. Cedano , is to check that everything is in accordance with the desired coding, generated document (html, js, css ...), web server, connections database server , database, tables, columns ... In short, all parties involved should be in the same coding.
Finally, let's see an example:
// Establecer codificación en las cabeceras enviadas para la petición http
header('Content-Type: text/html; charset=UTF-8');
// Conexión
$cCms= new mysqli("localhost", "mi_usuario", "mi_contraseña", "test");
// Estabecer codificación para la conexión
if (!$cCms->set_charset("utf8mb4")) {
printf("Error cargando el conjunto de caracteres utf8: %s\n", $cCms->error);
exit;
}
$consulta = "select valorOpcion from opciones where nombreOpcion='$nombre'";
$hacerConsulta = mysqli_query($cCms, $consulta) or die(mysqli_error($cCms));
if($hacerConsulta){
if(mysqli_num_rows($hacerConsulta)==1){
$fila = mysqli_fetch_array($hacerConsulta);
$valor = $fila['valorOpcion'];
}else if(mysqli_num_rows($hacerConsulta)>1){
$valor = "Error al obtener datos de $nombre [+1]";
}else{
$valor = "Error al obtener datos de $nombre [0]";
}
}else{
$valor = "Error al obtener datos de $nombre [-1]";
}
echo $valor;