I'm doing an insert with PHP PDO to a mysql database, I pass an array for the parameters, but it works and I get the following error SQLSTATE [HY093]: Invalid parameter number: parameter was not defined
this is the connection method
public function conectar(){
$conexion_mysql = "mysql:host=".$this->host.";dbname=".$this->base."";
$conexionBD= new PDO($conexion_mysql,$this->usuario,$this->password);
$conexionBD->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
//esta linea arregla la codificacion de caracteres utf8
$conexionBD->exec("set names utf8");
return $conexionBD;
}
here is the method where the transaction is executed
public function add(){
$sql="INSERT INTO PERSONAS
(PA_PAIS_ID,
PE_NOMBRE,
PE_CORREO,
PE_CLAVE,
PE_ESTADO)
VALUES(:PA_PAIS_ID,:PE_NOMBRE,:PE_CORREO,:PE_CLAVE,1)";
$arreglo=array(":PE_PAIS_ID"=>1,":PE_NOMBRE"=>"Jose Miguel",":PE_CORREO"=>"[email protected]", ":PE_CLAVE"=>123);
try {
$db = $this->conectar();
$ejecutar = $db->prepare($sql);
return $ejecutar->execute($arreglo);
} catch (PDOException $e) {
echo '{"error": {"text": '.$e->getMessage().'}';
}
}
also probe the query if it had syntax error but it does not have, which can be.