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_ERRMODE, PDO::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))
?>
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_ERRMODE, PDO::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($registro, 200, ",")) !== 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();
}
}
?>
Código HTML:
666555,mac'p¥Aato 777888,Array ñÑáéíóú
Alguna idea de cuál puede ser el problema? o qué estoy obviando?
![triste](http://static.forosdelweb.com/fdwtheme/images/smilies/frown.png)