Hi, I'm working with PHP and MySql with PDO and the model view controller (MVC) but I have an error when trying to do a SELECT * on the model side. My intrigue is that it works when I do INSERT INTO and when it's a SELECT. what I do is a validation of the existence of a record in the database and I apply rowCount () to know if it was successfully brought up and equal to 1 but always arrives 0 but the record does exist in the database
$datosUs=[
"clave_usuario"=>$usuario,
"contrasenia"=>$contrasenia
];
$datosCuenta=loginModelo::iniciar_sesion_modelo($datosUs);
if($datosCuenta->rowCount()==1){
$row = $datosCuenta->fetchAll();
and this sends it to the model
protected function iniciar_sesion_modelo($datos){
$sql=mainModel::conectarBD()->prepare("SELECT * FROM usuarios WHERE clave_usuario='RIVE' AND contraseña='123456' AND estatus=true");
$sql->bindParam(":clave",$datos['clave_usuario']);
$sql->bindParam(":contrasenia",$datos['contrasenia']);
$sql->execute();
return $sql;
}
my PDO function that calls the model
protected function conectarBD(){
$cadenaconexion = new PDO(SGBD,USER,PASS);
return $cadenaconexion;
}
**
-------------- ABOVE DOES NOT BRING ME A VALUE |
-------------- DOWN IF YOU BRING ME VALUES |
**
In my query, I do not use the bindParam, I just give it a value by assigning variables
$buscar_servicio=mainModel::consultas_simples("SELECT * FROM servicios WHERE clave_servicio='$clave_servicio'");
mainModel
**protected function conectarBD(){
$cadenaconexion = new PDO(SGBD,USER,PASS);
return $cadenaconexion;
}
//ejecucion de consultas simples para agilizar codigo
protected function consultas_simples($consulta){
$respuesta = self::conectarBD()->prepare($consulta);
$respuesta->execute();
return $respuesta;
}
when I make an insert
$guardar=servicioModelo::agregar_servicio_modelo($datos);
if($guardar->rowCount()>=1){
$alerta=[
"Alerta"=>"limpiar",
"Titulo"=>"¡Listo!",
"Texto"=>"El servicio se ah agreagado con exito.",
"Tipo"=>"success"
];
return mainModel::sweet_alert($alerta);
}else{
$alerta=[
"Alerta"=>"simple",
"Titulo"=>"Atención",
"Texto"=>"No se pudo agregar el servicio./nIntentelo nuevamente.",
"Tipo"=>"error"
];
return mainModel::sweet_alert($alerta);
}
model
protected function agregar_servicio_modelo($datos){
$sql=mainModel::conectarBD()->prepare("INSERT INTO servicios(clave_servicio,servicio,descripcion) VALUES(:clave,:servicio,:descripcion)");
$sql->bindParam(":clave",$datos['clave_servicio']);
$sql->bindParam(":servicio",$datos['servicio']);
$sql->bindParam(":descripcion",$datos['descripcion']);
$sql->execute();
return $sql;
}