Problems with special characters mysql php [duplicate]

1

well as I mention it: I have a simple database with a single table because it is a test where ALL (the database, the table, the text fields) is with a collation "utf8_general_ci" then to the time to read from php the text field that has ñññ''0ó annoying and appears exactly \ ' 0

consult.php:

<?php 

    require("conexion.php");

    header("Content-Type: text/html;charset=utf-8");

    $sql = "SELECT * FROM 'administrador'";

    $result = $mysqli->query($sql);

     $barrios = $result->fetch_assoc();

    $local = mysqli_real_escape_string($mysqli, $barrios['nombre']);

    echo $local;

?>

Database in mysql:

Table mysql:

table data:

Guys this is the most important thing in my project and I really can not find an exit If anyone knows what I should do, I really appreciate it

    
asked by DianaDiana 08.08.2017 в 04:29
source

1 answer

0

You can change the Collation of the table or the columns to:

utf8_spanish_ci

You must bear in mind that in HTML you must also include the following tag.

<meta charset="utf-8">

In the connection to the database you can do the following, to avoid bringing special characters errors.

Example:

<?php
    $c = @new mysqli('', '', '', '');
    if ($c->connect_error) {
        die('Error de conexión: ' . $c->connect_error);
    }
    if (!$c->set_charset("utf8")) {
        printf("Error cargando el conjunto de caracteres utf8: %s\n", $c->error);
        exit();
    }
?>
    
answered by 08.08.2017 / 04:40
source