I want to read a CSV file that has three fields: cod, nom and amount; and insert them into a table that has the following columns:
TABLA
cod integer
nom varchar(45)
importe decimal(8,2)
periodo integer
fecha date
This is the code:
$registro = fopen($ruta.$formato_archivo, "r");
while (($data = fgetcsv($registro, 4096, ",")) !== FALSE) {
$sth = $BD->prepare("INSERT INTO tabla (cod, nom, importe)
VALUES (:cod, :nom, :importe)");
$cod = $data[0];
$nom = $data[1];
$importe = $data[2];
$sth->bindParam(':cod', $cod, PDO::PARAM_STR);
$sth->bindParam(':nom', $nom, PDO::PARAM_STR);
$sth->bindParam(':importe', $importe, PDO::PARAM_STR);
$sth->execute();
}
And it shows me the error:
Invalid parameter number: number of bound variables does not match number of tokens in line (line of execute ()).
And it does not insert any record.