Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/05/2016, 16:21
Avatar de bandolera
bandolera
 
Fecha de Ingreso: abril-2009
Mensajes: 613
Antigüedad: 15 años
Puntos: 7
Pregunta Carga masiva no reconoce caracteres especiales

Cuando inserto caracteres especiales de esta manera sí graba en mi tabla de trabajo:
Código PHP:
<?php
class ConexionDB extends PDO {
  public function 
__construct () {
  try {
  
parent:: __construct('mysql:host=localhost;dbname=xprueba;charset=utf8''root','clave');
  
parent:: setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
  } catch (
Exception $ex) { die ('Database is not exist');  }  }
  function 
__destruct(){
  }
}

  
$BD = new ConexionDB();
  
$sth $BD->prepare("INSERT INTO xxx (codigo, stud) VALUES (:codigo, :nombre)"); 
//------- CON BINDPARAM
  
$codigo "666555";
  
$nombre   "mac'p¥Aato";

  
$sth->bindParam(':codigo'$codigo);
  
$sth->bindParam(':nombre'$nombre);
  
$sth->execute();
//------- CON ARRAY
  
$codigo "777888";
  
$nombre "Array ñÑáéíóú";

  
$sth->execute(array(':codigo'=>$codigo':nombre'=>$nombre))
?>
Pero si leo de un archivo csv no los reconoce.
Código PHP:
<?php

class ConexionDB extends PDO {
  public function 
__construct () {
  try {
  
parent:: __construct('mysql:host=localhost;dbname=xprueba;charset=utf8''root','clave');
  
parent:: setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
  } catch (
Exception $ex) {  die ('Database is not exist');   }  }
  function 
__destruct(){
  }
}
  
$BD = new ConexionDB();
    if(
file_exists('prueba_caracteres.csv')) {
        
$registro fopen('prueba_caracteres.csv'"r");
        
$BD = new ConexionDB();
        while ((
$data fgetcsv($registro200",")) !== FALSE) {
            
$sth $BD->prepare("INSERT INTO xxx (codigo, nombre) VALUES (:codigo, :nombre)");
            
$codigo $data[0];
            
$nombre   $data[1];

                        
$sth->bindParam(':codigo'$codigo);
                        
$sth->bindParam(':nombre'$nombre);
                        
$sth->execute();
        }
    }
?>
Mi archivo csv tiene lo siguiente:
Código HTML:
666555,mac'p¥Aato
777888,Array ñÑáéíóú
Pero se trunca no reconoce las ñ's ni las tildes que es lo más importante.
Alguna idea de cuál puede ser el problema? o qué estoy obviando?
__________________
Todos somos iguales. NO! a la violencia de género.