0
When I press the LOAD button on my portfolio, the $NAME and $TYPE Click when you have some kind of accent. The first 6 blocks of the portfolio that are already loaded with the page, are in UTF8 but the others are not. Check out the website: somospixel.com/test in the PORTFOLIO part
<?php
function fn_conexao(){
$dbuser = "######";
$dbpass = "#####";
try {
$pdo = new PDO('mysql:host=#####;dbname=#####', $dbuser, $dbpass);
$pdo -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$pdo->exec("SET CHARACTER SET utf8");//corrige os acentos na hora de gravar no BD
} catch(Exception $e) {
echo 'Erro na conexao: ' . $e->getMessage();
}
return $pdo;
}
function dados($pdo){
try {
if(!isset($_GET['id']) or $_GET['id'] == null){
$id = 0; //se o GET nao for enviado o for enviado como nullo , a variável ID pega o valor de 0
}else{
$id = $_GET['id']; //pega o valor passado via GET
}
$arr = array();
$sql = "ALTER DATABASE pot CHARSET = UTF8 COLLATE = utf8_general_ci";
$sql = "SELECT * FROM pot WHERE id < $id ORDER BY id DESC LIMIT 6";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$linha = $stmt->fetchAll(PDO::FETCH_ASSOC);
if($stmt->rowCount() >= 1){
return $linha; //retorna o resultado da query
}else {
return 0;
}
} catch(Exception $e) {
print 'Erro ao inserir os dados no banco: ' . $e->getMessage();
$conexao = desconecta($conexao);
}
}
$conexao = fn_conexao();
$dados = dados($conexao);
$dados = json_encode($dados); //converte o resultado para json
print $dados; //imprime os dados na tela
?>
in the head of html:
<meta charset="UTF-8">
– Brumazzi DB
I gave a scanned on your site, and I realized that your data already comes with the wrong server charset even, so the problem is not time to show in HTML. I tried to play your problem here by placing accented strings in my mysql and making request of this data, all OK... Maybe your problem is time to send the data over the HTTP server, so what you need to do is add the correct charset to Apache (if this is your HTTP server). Vide 1 and 2
– tayllan
@tayllan I didn’t understand how I’ll make him send with the right charset
– kaiquemix
so @kaiquemix, I just kicked what could solve your problem: setting up Apache to use the UTF-8 charset. But at the same time I find it difficult to be your problem, and I don’t understand much more of this to be able to help you :(. No link that I commented on above there is a people discussing about how they fixed similar problems, maybe it helps.
– tayllan
@tayllan am using hostgator phpadmin for this..
– kaiquemix
um, hosting service. Eh, can’t help you anymore :(
– tayllan