Problems with the UTF-8 encoding in mysql

0

I have problems with the character encoding with the ñ and tildes, the page is in utf-8 and the table and the DB in utf-8_general_ci but it happens as in the following image.

Any solution?

$ connection = new mysqli ($ host, $ userdb, $ clavedb, $ database);

    
asked by Daniel 17.06.2017 в 21:24
source

2 answers

1

I leave you a possible example:

//Tu conexión
$conexion = new mysqli($host,$usuariodb,$clavedb,$basededatos);

//Comprobamos conexión.
if ($conexion->connect_error) {
    die("La conexión fallo: " . $conexion->connect_error);
}

//Caracteres UTF-8.
if (!$conexion->set_charset("utf8")) {
    printf("Error cargando el conjunto de caracteres utf8: %s\n", $conexion->error);
    exit();
}

//Añades tu sentencia.

Manual mysqli :: set_charset

    
answered by 17.06.2017 / 23:29
source
0

After creating the connection and before inserting:

$conexion->set_charset('utf8');
    
answered by 17.06.2017 в 23:12