problemas com insert através do PHP em tabela Mysql
Pessoal, boa noite!
Criei um script de teste para fazer insert em uma tabela Mysql mas esta gravando "São Paulo" com caracteres especiais.
Esta gravando assim: São Paulo
Tabela Dados com 2 campos
id int
nome varchar
Collation = utf_unicode_ci
Script de Teste:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of testeInsert
*
* @author Raffael
*/
class testeInsert {
private $conn;
private $nome;
public function abreConexao() {
try {
$this->conn = new PDO('mysql:host=localhost;dbname=teste', 'root', '');
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
public function gravaDados() {
try {
$this->nome="São Paulo";
$query = "INSERT INTO dados(nome) VALUES('{$this->nome}')";
$stmt = $this->conn->prepare($query);
$stmt->execute();
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
}
header("Content-type: text/html;charset=utf-8");
$obj = new testeInsert();
$obj->abreConexao();
$obj->gravaDados();Discussão (18)
Carregando comentários...