Welcome Guest, Not a member yet? Register   Sign In
Query returns results using bad encoding
#1

[eluser]jstuardo[/eluser]
Hello...

I have an encoding problem now.

Well, I have spanish characters stored in a database. When I retrieve data, they are shown in an encoding similar to UTF-8. I write "similar" because when I use UTF-8 encoding in the HTML page, the characters aren't shown correctly.

I have this configuration now:

Code:
$config['charset'] = "ISO-8859-1";

and this is inside the HEAD tag of the page:

Code:
$meta = array(
              array('name' => 'robots', 'content' => 'no-cache'),
              array('name' => 'description', 'content' => $evento->nombre),
              array('name' => 'keywords', 'content' => $evento->nombre . ', ' . $evento->palabras_clave),
              array('name' => 'Content-type', 'content' => 'text/html; charset=iso-8859-1', 'type' => 'equiv')
    );

<?php echo meta($meta)?>

Well, I am executing this query:

Code:
$sql = 'select lp.id,
                       c.nombre as nombre_comuna,
                       lp.nombre as nombre_lugar,
                       lp.direccion
                from lugar_pago lp, lugar_pago_x_evento lpxe, comuna c
                where lpxe.lug_id = lp.id and
                      c.id = lp.com_id and
                      lp.activo = 1 and
                      lpxe.eve_id = ?';

The nombre_comuna field contains the string "Ñuñoa" and it was correctly stored because I use MySQL Query Browser to see the data. But when I return the data using:

Code:
$query = $this->db->query($sql, array('id' => $id));
return $query->result();

The following string is shown in the page: Ñuñoa

Any help will be greatly appreciated
Thanks

Jaime
#2

[eluser]slowgary[/eluser]
Have you tried setting $config['charset'] to 'UTF-8'?
Code:
$config['charset'] = 'UTF-8';
#3

[eluser]jstuardo[/eluser]
That was the default. I changed it to ISO-8859-1.
#4

[eluser]jstuardo[/eluser]
Never mind. The problem was in database.php configuration file. I changed the default value to:

Code:
$db['default']['char_set'] = "latin1";
$db['default']['dbcollat'] = "latin1_spanish_ci";

and it worked.

Jaime




Theme © iAndrew 2016 - Forum software by © MyBB